• Resolved bh

    (@bh)


    I am using WordPress as a CMS for most of the site, but I still have a blog in 2 sections. I did this by creating a page called “press”, and then set this page to use a “press.php” template that calls query_posts() to pull all posts for a particular category. I have a subnav that shows all the 2nd level pages which is queried by wp_list_pages() showing the post_parent. This works great.

    However, I run into problems when I click on a post permalink. The template switches from press.php to index.php and since this is a straight blog post there is no template or page hierarchy. The blog post doesn’t know where it belongs, and so doesn’t know which subnav items to display, etc.

    My question is, how can this blog post know that it is part of a Pages hierarchy with parent/child pages.

    I have cheated by passing a parentID in the query string, but this doesn’t work when using the_content/read more.

    Alternatively, is there a way to keep the permalink detail page at press.php instead of switching to index.php?

    My apologies if I haven’t explained this correctly, but I look forward to your response.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter bh

    (@bh)

    Just to clarify, I have this type of structure

    – Top Page – (/toppage/)
    — Sub Page (using template that shows blog posts) – (/toppage/subpage/)
    — Post – (/month/day/year/title)

    If I click through to the 3rd level post the URL changes and $post->post_parent returns 0.

    How can I be on the 3rd level post page and have it return the parent ID of the sub page?

    Thread Starter bh

    (@bh)

    I resolved this by adding this code to index.php

    if (is_single()){
     	if (in_category('Cat1')){
    		//set the section
    	} elseif (in_category('Cat2')){
    		//set the section
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get Post Parent if run from a template’ is closed to new replies.