Support » Themes and Templates » Filter posts on Home view – my solutions and failures.

  • The website:
    The theme: MistyLook v3.2.

    Objective: To simulate “filtering” what is displayed on the main/front page.

    I will be making regular posts in 3 main categories on my site. Those are Meanderments, Ponderments, and Ponder Live!.

    Using the buttons along the top. I want it to “feel” as though nothing is changing except for the content being displayed when switching between each of those three categories.

    I’ve tried accomplishing this a number of ways, yet each one falls short only slightly.

    As you see it now, this is how I would like it to display the posts, when switching in between the three top menu buttons (Meanderments, ponderments, and Ponder live!). This is the closest I have gotten to achieving my goals. I fall short only in aesthetics. In its current form, the buttons on the menu do not stay highlighted after selection. Making it difficult to decern the filter currently being applied to the post view.

    The reason it does this is…

    Method 1) <i>(this is the method I’m currently using)</i> In this method I used the Forwarding plugin. I then set each of those three pages to forward to the category view of that category correlating with its name. Thus, because the view forwards, and ends up on a category view it does not highlight the top-menu button. Also to achieve the look of only the articles showing I had to modify the Archive.php to not display any headline for those three categories.

    Method 1 problem: Top-menu items do not stay highlighted (though the other buttons such as About Ponder Place do)

    Method 2) In this method I copied and modified the code from Archive.php and created templates for each category, named like “category-#.php” correlating with the database IDnumber for the 3 categories. I then added in the code ‘<?php query_posts(‘category_name=categoryname&showposts=10′); ?>’ in order to pull the appropriate category content.

    I then set each page to use its own template modified for its own category.

    Method 2 problem: Something in the Archive.php code was stripping it from using the <!--more--> function. Thus my posts were showing up in full form, minus pictures. I believe this is due to the Archive being set to pull the_excerpt(). Which I’ve been unsuccessful in modifying to show full post content instead.

    I hope I’ve made sense.

    Again, as the site stands right now, as function and post display goes is how i want it. It is just not highlighting those top-menu buttons.

Viewing 11 replies - 1 through 11 (of 11 total)
  • So basically, the only thing with #1 is – lack of highlighting?
    (everything is there)

    Method #2 has quite a wrong approach!
    No need to add any query_post tag to the category template. WP is smarter than you… think 🙂 If the category-X.php exists, it will select it to display cat=X without your intervention!

    Though your link is what I was looking for. I can conclude from the link that my implementation in method #1 is fundamentally broken. In order to fix the menu highlight option, which this theme correctly implements. I have to break the theme by making it think the /category/meanderment requires highlighting.

    And as you pointed out, Method #2 is also unnecessary/redundent doing the query. However it looks like that is, at least on a theoretical level, is more along the path to the correct solution.

    Which solution, as far as i can tell at this point; is to create a template which calls for posts under a certain category. And while I was able to achieve that by copying the Archive.php code into a new template file. The problem in that implementation, is that, for posts displayed where only showing as excerpt(), as the archive.php calls for. This kills the whole “filter” idea, or the idea that you are just switching between which posts are being displayed.

    I’ve tried messing with the excerpt() part in archive.php but have not been successful in changing it to the_content().

    crap, i just screwed it up trying to implement a specific category being listed on a page….FYI the current implementation as seen on the site may very as i’m screwing around with it.

    Please leave any suggestions on how i can accomplish listing posts belonging to a specific category on a Page.

    You never mentioned till now you wanted the posts on a Page. To be honest, I don’t have an answer for that – never thought about listing posts on a Page… since Pages were not designed (developed) for that.
    I think the Category Templates do exactly that: list all the posts belonging to their specific category. Whether to display whole post, post up till the “more” tag or an excerpt – that’s easy: just use the proper template tag.

    did you change “the_excerpt” to “the_content”, in all these new category-x files ?


    @rudolf45 – Sorry for the confusion. I looked into Tags for a short while. I’ll have to continue looking into this.

    @sadish – I tried this once before, and on your suggestion, I’ve implemented it again. Look at the site now. As you can see, it is not recognizing/”heeding” the <!--more--> in each post. Though it does list the “Read Full Post” after it has listed the full post.

    FYI: the <!--more--> tag and the_excerpt template tag are 2 different things and they don’t work together. It’s an “either/or” situation.

    Inserting the “more” is a manual action while writing the post and where you want it.
    The excerpt just takes X number of words and displays them. No human interaction needed.

    I do understand they are different. In essence what I want are 4 front pages. One that displays all posts, and another for each specific category (there are 3). I wanted it to appear as though Posts were just being filtered when switching between the categories/types-of-posts. This is why I chose to go with the <!--more--> tag. That would allow me flexibility with my posts, and allow pictures etc.

    I’ve had a chance to look at Template Tags again. It seems templates is the only way to achieve what I would like to. I’m just having trouble making sense of it all.

    Are there any resources for basic templates? or is that specific to the theme and thus would need to come from the theme author?

    I’ve taking various .php files from the theme (archive.php, index.php, page.php, etc) and tried stripping them down to what I understand a template to be. No success thus far.

    In essence what I want are 4 front pages. One that displays all posts, and another for each specific category (there are 3).

    That would mean:
    – 1 index.php (in your theme directory)
    – 1 archive.php file
    or, in case you want differently styled category listing display:
    + 1 category.php file

    WP is doing all the hard work for you, so I don’t really get where your problem is.
    According to the Template Hierarchy when displaying a list of posts in a certain category, WP will look first for a category-XX.php (XX being the cat ID) to display the posts.. then if not found for category.php, if not found > for archive.php – and finally, for inedx.php, as the general fallback for everything.

    And no, you do NOT need to put any special query into those template files, just the regular Loop; i.e. copying and saving the archive.php or index.php as category.php should do the job.
    Of course, having more and more specialized templates gives you the opportunity to style them a bit differently or use different template tags etc.

    And no, you can not have 4 “frontpages”. You have one: the index.php. The others might look exactly the same, but don’t call them “frontpage”. Those are simply category archives listings. (In this way everybody will understand what are you talking about 🙂

    When I say “I want are 4 front pages” I’m referring to the appearance of 4 front pages, ie smoke and mirrors. I realize its not practical to think of them all as actual front pages. But from a visitor standpoint, it might as well be 4 front pages…though its 1 front page + 3 category pages made to look exactly like the front page. Perhaps what I’m trying to do is beyond WordPress’ ability without my knowing PHP.

    Anyway, I’m now back to method 1. And I’ll just live with the fact that my menu items will not stay highlighted.

    I do not consider this a win but I’m tired of trying to figure it out. Thank you rudolf45 for all the attention you’ve given my thread.

    Any suggestions, please let me know, I’ll keep an eye on this thread. And revisit the issue at a later time.

    Well, here is what I’d do: Instead of using the wp_list_page tag, I’d hardcode ALL the 4-5 links in the top menu to link to the Pages or categories I need, and then apply the first “dynamic menu” method described on the Codex page I’ve linked to above. (section #4)

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Filter posts on Home view – my solutions and failures.’ is closed to new replies.