WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Using The Loop on a template page means current_page_parent is the blog page?

[Resolved] Using The Loop on a template page means current_page_parent is the blog page?

  • Hi all,

    I’m building a new theme for a web design company, and it has a number of top level pages (Home, About, Portfolio, Blog, etc..). These pages are listed in the header using wp_list_pages()

    On the portfolio page, I applied a specific template, specially made for the portfolio page.

    I use query_posts and The Loop to populate this page with posts from the blog that have the category “portfolio”.

    If I remove The Loop, when I’m on the portfolio page, it’s
    <li> in the header has the class current_page_item, and if I keep it in, my main blog page in the header has the class current_page_parent, and my portfolio looses its current_page_item class.

    This means that WP thinks that just because I use The Loop, my page must be a child of the blog, which is not always the case.

    Is there any way I can change this behavior?

Viewing 5 replies - 1 through 5 (of 5 total)
  • If you use query_posts you are modifying the main page loop. That may be why you are noticing this. Its mostly just a guess though. I’ve never paid much attention to how the classes is wp_list_pages are generated.

    I’d bet there’s a variable you can set to trick the page…

    I’ll have a look for you tomorrow(today here), after i’ve had some sleep..

    Yeah, I’d have no problem using wp_list_pages, as that does not mess with any css classes, but as far as I know, I can’t use wp_list_pages to get a post’s thumbnail, excerpt, title and permalink, since it does not return a post ID (hell, I think it only works for pages!)

    wp_get_archives is the same deal, since I cant iterate through the results with a while or foreach loop, and use an ID to get what I need using the get_post_* functions.

    It seems kind of odd that WP would make the broad assumption that query_post means main page loop.

    It seems kind of odd that WP would make the broad assumption that query_post means main page loop.

    Its not an assumption. Its the way the code is written and its clearly stated in the docs. If you want to make another loop there are ways to do that.

    @apljdi

    Thanks for that, I forgot you could have your own WP_Query class, and that the class is not the same as query_posts.

    Replacing query_posts with the new class solved my issues – wp_list_pages works like I need it to.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Using The Loop on a template page means current_page_parent is the blog page?’ is closed to new replies.
Skip to toolbar