<?xml version="1.0" encoding="UTF-8"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>ThemeShaper Forums Topic: Customize Page Posttitle to include Ancestor/Parent Page Info</title>
<link>http://themeshaper.com/forums/</link>
<description>Help In Shaping WordPress Themes</description>
<language>en</language>
<pubDate>Tue, 21 May 2013 20:51:45 +0000</pubDate>

<item>
<title>wlanni on "Customize Page Posttitle to include Ancestor/Parent Page Info"</title>
<link>http://themeshaper.com/forums/topic/customize-page-posttitle-to-include-ancestorparent-page-info#post-18963</link>
<pubDate>Fri, 04 Feb 2011 08:49:39 +0000</pubDate>
<dc:creator>wlanni</dc:creator>
<guid isPermaLink="false">18963@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Hello!&#60;/p&#62;
&#60;p&#62;I'm building out a luxury bed site.&#60;/p&#62;
&#60;p&#62;Basically, what I needed to do was on specific bed model pages using a specific template I created, I needed to include the bed brand name before the model name. On the parent brand page, I didn't want the brand name to repeat itself. And then on other pages using the same template (like accessories pages, etc) I didn't want them to try to grab their parent page title.&#60;/p&#62;
&#60;p&#62;I found a really great function that uses get_post_ancestors to check if a page is a child of another page. I combined that then with rewriting thematic_postheader_posttitle. &#60;/p&#62;
&#60;p&#62;Was there a better/more efficient way of writing this so that I ONLY had to write the if statements for my custom page templates, vs having to include ALL the cases for everything else (404, is_single, is_page, etc)?&#60;/p&#62;
&#60;p&#62;Also, I tried originally to write this as a function called &#60;strong&#62;childtheme_override_postheader_posttitle&#60;/strong&#62; but I couldn't figure out how to get that to work, so I gave up.&#60;/p&#62;
&#60;p&#62;Here's what I did:&#60;br /&#62;
First function pulled from here: &#60;a href=&#34;http://codex.wordpress.org/Conditional_Tags&#34;&#62;Conditional Tags &#38;gt; WordPress Codex&#60;/a&#62;&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;//function to check if page is child of another page
function is_tree($pid) { // $pid = The ID of the page we’re looking for pages underneath
	global $post; // load details about this page
	$anc = get_post_ancestors( $post-&#38;gt;ID );
	foreach($anc as $ancestor) {
		if(is_page() &#38;#38;&#38;#38; $ancestor == $pid) {
			return true;
		}
	}
	if(is_page()&#38;#38;&#38;#38;(is_page($pid)))
		return true; // we’re at the page or at a sub page
	else
		return false; // we’re elsewhere
};&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Then I wrote in some if statements to check for the page template, and to rewrite posttitles on children of specific pages:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;//update product page titles to include brand name
function product_page_has_brandname()  {
	global $post;
//Had to check if a page is_page, and then also make sure it isn&#38;#39;t my specific template, to write the normal &#38;lt;h1&#38;gt; title
     if (is_single() &#124;&#124; is_page() &#38;#38;&#38;#38; !is_page_template(&#38;#39;products.php&#38;#39;)) {
	        $posttitle = &#38;#39;&#38;lt;h1 class=&#38;quot;entry-title&#38;quot;&#38;gt;&#38;#39; . get_the_title() . &#38;quot;&#38;lt;/h1&#38;gt;\n&#38;quot;;

//check if page is using my template, and then is part of one of the brand trees
	    } elseif (is_page_template(&#38;#39;products.php&#38;#39;) &#38;#38;&#38;#38; is_tree(73) ) {
	    	if (is_page(73)) {
	    		$posttitle = &#38;#39;&#38;lt;h1 class=&#38;quot;entry-title&#38;quot;&#38;gt;&#38;lt;img src=&#38;quot;&#38;#39;;
	    		$posttitle .= get_stylesheet_directory_uri();
	    		$posttitle .= &#38;#39;/images/logo-hastens-bk.png&#38;quot; alt=&#38;quot;&#38;#39; . get_the_title(73) . &#38;#39;&#38;quot; width=&#38;quot;166&#38;quot; height=&#38;quot;51&#38;quot; /&#38;gt;&#38;lt;/h1&#38;gt;&#38;#39;;
	    	} else {
	    		$posttitle = &#38;#39;&#38;lt;h1 class=&#38;quot;entry-title&#38;quot;&#38;gt;&#38;lt;span class=&#38;quot;page-ancestor&#38;quot;&#38;gt;&#38;#39; . get_the_title(73) . &#38;#39;&#38;lt;/span&#38;gt; &#38;#39; . get_the_title() . &#38;quot;&#38;lt;/h1&#38;gt;\n&#38;quot;;
	    	}
	     } elseif (is_page_template(&#38;#39;products.php&#38;#39;) &#38;#38;&#38;#38; is_tree(71)) {
	    	if (is_page(71)) {
	    		$posttitle = &#38;#39;&#38;lt;h1 class=&#38;quot;entry-title&#38;quot;&#38;gt;&#38;lt;img src=&#38;quot;&#38;#39;.get_stylesheet_directory_uri() . &#38;#39;/images/logo-vispring-bk.png&#38;quot; alt=&#38;quot;&#38;#39; . get_the_title(71) . &#38;#39;&#38;quot; width=&#38;quot;174&#38;quot; height=&#38;quot;43&#38;quot; /&#38;gt;&#38;lt;/h1&#38;gt;&#38;#39;;
	    	} else {
		    	$posttitle = &#38;#39;&#38;lt;h1 class=&#38;quot;entry-title&#38;quot;&#38;gt;&#38;lt;span class=&#38;quot;page-ancestor&#38;quot;&#38;gt;&#38;#39; . get_the_title(71) . &#38;#39;&#38;lt;/span&#38;gt; &#38;#39; . get_the_title() . &#38;quot;&#38;lt;/h1&#38;gt;\n&#38;quot;;
	    	}
	    } elseif (is_404()) {
	        $posttitle = &#38;#39;&#38;lt;h1 class=&#38;quot;entry-title&#38;quot;&#38;gt;&#38;#39; . __(&#38;#39;Not Found&#38;#39;, &#38;#39;thematic&#38;#39;) . &#38;quot;&#38;lt;/h1&#38;gt;\n&#38;quot;;
	    } else {
	        $posttitle = &#38;#39;&#38;lt;h2 class=&#38;quot;entry-title&#38;quot;&#38;gt;&#38;lt;a href=&#38;quot;&#38;#39;;
	        $posttitle .= apply_filters(&#38;#39;the_permalink&#38;#39;, get_permalink());
	        $posttitle .= &#38;#39;&#38;quot; title=&#38;quot;&#38;#39;;
	        $posttitle .= __(&#38;#39;Permalink to &#38;#39;, &#38;#39;thematic&#38;#39;) . the_title_attribute(&#38;#39;echo=0&#38;#39;);
	        $posttitle .= &#38;#39;&#38;quot; rel=&#38;quot;bookmark&#38;quot;&#38;gt;&#38;#39;;
	        $posttitle .= get_the_title();
	        $posttitle .= &#38;quot;&#38;lt;/a&#38;gt;&#38;lt;/h2&#38;gt;\n&#38;quot;;
	   }
   return $posttitle;
} // end postheader_posttitle
add_filter(&#38;#39;thematic_postheader_posttitle&#38;#39;,&#38;#39;product_page_has_brandname&#38;#39;);&#60;/code&#62;&#60;/pre&#62;</description>
</item>

</channel>
</rss>
