Forums

wp_list_pages with forced highlight (7 posts)

  1. gmisen
    Member
    Posted 4 months ago #

    So I use wp_list_pages for my blogs menu. I have different pages to list different categories of posts.

    The problem is, if my reader is looking at a single post that was listed on the "JOBS" page, I would want the menu to still be up top with the JOBS page highligthed (b/c you just came from there)

    But since the command is just <?php wp_list_pages(); ?> I'm not sure how to specify this through conditional statements (or any other way)

    I'd preferably like to not hand code this, so that if anyone else adds a page they wont have to come back and redo it.

    Any ideas of what I could do? Anyone done anything like this before?

    Thanks for any help!!!

  2. esmi
    Member
    Posted 4 months ago #

    Have you tried styling .current_page_item and .current_page_ancestor?

  3. Rhand
    Member
    Posted 4 months ago #

    Why don't you use a bread crumb plugin? Like that people see where they came from and can return easily.
    Or use Esmi's suggestion. ..

  4. Otto42
    Moderator
    Posted 4 months ago #

    esmi's answer is the correct one. Look at the XHTML that the wp_list_pages() call generates. If you're looking at a page, then that page's link gets special classes which you can style however you like.

  5. gmisen
    Member
    Posted 4 months ago #

    i have tried styling it, not sure if i understand exactly how current_page_ancestor works but im still playing with it.

    Where I'm listing my pages is on a single post, so it has no inherent connection to any of the pages (except that main blog I guess)

    I suppose my question is, how can I call wp_list_pages and add a condition, "if (pageX) comes up in the returned results, then apply the .current_page_item class to it"

    if it can be done. I may have to cave and hand-code the menu for the single pages

  6. Otto42
    Moderator
    Posted 4 months ago #

    Ahh, I see your problem. I missed it in your first post:

    I have different pages to list different categories of posts.

    Fail. You fell into a classic trap. You saw that your theme made tabs or something similar for the Pages using wp_list_pages. You wanted these to be categories. So you made a Page for each Category then used some form of trickery to put Posts from the categories on those Pages.

    What you should have done instead is to modify the call to wp_list_pages and either replace it or add to it with a call to wp_list_categories.

    See, WordPress has the ability to display lists of posts in specific categories built right into it. No need for messing about with creating Pages and such. If you had used wp_list_categories, then you'd get the category pages automatically, and it'd have classes in there like current_cat and so forth for you to style with.

  7. gmisen
    Member
    Posted 3 months ago #

    this is actually no big deal, its kindof just annoying. but just to put it out there

    I do suspect that I am overly complicating things. But we're using wordpress as a Content Management System so it's pretty complicated already.

    Our main Content blog has many categories in it, recurring features etc, probably 20 or so.

    But outside of the blog we have the 'About Us' stuff that is not part of the Blog Content --- Writers, Job Listings, Press Resources -- all as separate listings (posts).

    I created categories for these different things so it would be easy (so i thought) to exclude them from the normal blog roll as well as make the non-Blog Content side of the blog easy for people to add to, rearrange, edit and update from the WP admin interface (just like they do with the blog.

    So theres only about 5 categories out of 25 I want to list. Because the 'Jobs' postings demand a separate page where a 'weekly link roundup' blog post listing isnt more than a normal category page on the Blog side. I made a page for each of the Menu Categories (b/c a couple of those pages list more than one categories on it)

    I guess I'm just curious if anyone else out there has experience managing all these different types of posts. Like I say, I could very well be overcomplicating things, so if anyone has advice for streamlining things, I am all ears!

    Thanks!

Reply

You must log in to post.

About this Topic