<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WP Engineer &#187; Tags</title>
	<atom:link href="http://wpengineer.com/tag/tags/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Mon, 21 May 2012 22:48:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pages &amp; Subpages &#8211; Is Parent?</title>
		<link>http://wpengineer.com/921/pages-subpages-is-parent/</link>
		<comments>http://wpengineer.com/921/pages-subpages-is-parent/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 13:07:30 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Tags]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=921</guid>
		<description><![CDATA[WordPress allows to create sub-pages in your backend. This is why many uses WordPress as a CMS. Sometimes you like with the help of the Conditional Tags to start several queries with a certain respond &#8211; but then you see frequently in the template static queries on any ID of a page. But it's possible [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/wp_subpage.png" alt="wp_subpage" title="wp_subpage" width="202" height="134" class="alignright size-full wp-image-922" /><br />
WordPress allows to create sub-pages in your backend. This is why many uses WordPress as a CMS. Sometimes you like with the help of the Conditional Tags to start several queries with a certain respond &#8211; but then you see frequently in the template static queries on any ID of a page.<br />
But it's possible to handle this differently, and simpler when it comes to pages or sub-pages of this page.</p>
<p>With this solution you can, for example, in dependence of a page, load a specific layout. This small request I'll take as an example and show a function that gives queries to pages / sub-pages and I will show an example in action.<br />
<span id="more-921"></span></p>
<h3>Background</h3>
<p>If you create in WordPress a new page, then you can define it in the attributes as a subpage of an existing page. This can not only create tree views, but also structures which are not uncommonly needed in a CMS.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/wp_subpage_new.png" alt="wp_subpage_new" title="wp_subpage_new" width="285" height="388" class="aligncenter size-full wp-image-923" /></p>
<p>If you want control the output depending on the page, then you use the Conditional Tag <code><a href="http://codex.wordpress.org/Function_Reference/is_page">is_page()</a></code>, which you use to implement the requirement. For not using the tag for every page and use the template constantly, you can use a simple function, which queries the main page and returns a true back (<code>true</code>) when there is a subpage of the main page.</p>
<h3>Solution</h3>
<p>This function, the following syntax is used in the <code>functions.php</code> of the theme.</p>
<pre lang="php">
// check ID post and child-post
function has_parent( $post, $post_id ) {
	if ($post-&gt;ID == $post_id)
		return true;
	elseif ($post-&gt;post_parent == 0)
		return false;
	else
		return has_parent( get_post($post-&gt;post_parent), $post_id );
}
</pre>
<p>This little function checks whether the output page is a page or subpage of a page with the passed ID; sounds complicated, but it really isn't. This feature can be, after put in the theme, be used in all the templates now. The following example checks whether it is a page or subpage of the ID 1, and if so, then the stylesheet Alternative 1 (<code>alternative_1.css</code>) will be output.</p>
<p>Otherwise will be ID 2, or if it doesn't fit to none of the queries, then the default stylesheet will be used.</p>
<p>To have the ability to expand a little, I set in the query variable <code>$bodyclass</code> that I output in the body-tag. Thus I have an additional point and depending on the page to realize an according design. </p>
<pre lang="php">
    &lt;?php
    $bodyclass = &#039;&#039;;
    if ( function_exists(&#039;has_parent&#039;) ) {
	    if ( has_parent($wp_query-&gt;post, 1) ) {
	        echo &#039;&lt;link rel=&quot;stylesheet&quot; href=&quot;&#039; . get_bloginfo(&#039;stylesheet_directory&#039;) . &#039;/alternative_1.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;&#039; . &quot;\n&quot;;
	        $bodyclass = &#039;class=&quot;alternative_1&quot;&#039;;
	    } elseif ( has_parent($wp_query-&gt;post, 2) ) {
	        echo &#039;&lt;link rel=&quot;stylesheet&quot; href=&quot;&#039; . get_bloginfo(&#039;stylesheet_directory&#039;) . &#039;/alternative_2.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;&#039; . &quot;\n&quot;;
	        $bodyclass = &#039;class=&quot;alternative_2&quot;&#039;;
	    } else {
	    	echo &#039;&lt;link rel=&quot;stylesheet&quot; href=&quot;&#039; . get_bloginfo(&#039;stylesheet_directory&#039;) . &#039;/default.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;&#039; . &quot;\n&quot;;
	    }
  	} ?&gt;

&lt;/head&gt;
&lt;body&lt;?php echo &#039; &#039; . $bodyclass; ?&gt;&gt;
</pre>
<h3>Conclusion</h3>
<p>I think that this small possibility can have a large effect in the output and can have various possibilities. Also this solution can be realized with the change of a theme, which I mentioned in the article &#8222;<a href="http://wpengineer.com/change-your-wordpress-theme-on/">Change your WordPress Theme on Dependency</a>&#8220;.</p>
<p>Thank you for reading and even more I thank you for contributing any improvements in the comments section.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/921/pages-subpages-is-parent/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Show Amount Of Posts, Pages, Categories, Tags, Comments For WordPress Themes</title>
		<link>http://wpengineer.com/38/show-amount-of-posts-pages-categories-tags-comments-for-wordpress-themes/</link>
		<comments>http://wpengineer.com/38/show-amount-of-posts-pages-categories-tags-comments-for-wordpress-themes/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 18:03:47 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[counter]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[Tags]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=38</guid>
		<description><![CDATA[It looks like showing total amount of posts, pages and some other statistical values are very popular right now. I received many inquiries how to show statistical values on your front end. Following solution only works with WordPress 2.5 or higher. If you need help for a lower version, let me know in the comment [...]]]></description>
			<content:encoded><![CDATA[<p>It looks like showing total amount of posts, pages and some other statistical values are very popular right now. I received many inquiries how to show statistical values on your front end. </p>
<p>Following solution only works with WordPress 2.5 or higher. If you need help for a lower version, let me know in the comment field and I'll try to help.<br />
<span id="more-38"></span></p>
<h3>Number of posts</h3>
<pre lang="php">
$num_posts = wp_count_posts( &#039;post&#039; );
$num_posts = $num_posts-&gt;publish; //publish, draft
</pre>
<h3>Number of pages</h3>
<pre lang="php">
$num_pages = wp_count_posts( &#039;page&#039; );
$num_pages = $num_pages-&gt;publish; //publish
</pre>
<h3>Number of categories</h3>
<pre lang="php">
$num_cats  = wp_count_terms(&#039;category&#039;);
</pre>
<h3>Number of Tags</h3>
<pre lang="php">
$num_tags  = wp_count_terms(&#039;post_tag&#039;);
</pre>
<h3>Number of comments</h3>
<pre lang="php">
$num_comm  = get_comment_count();
$num_comm  = $num_comm&#091;&#039;approved&#039;&#093;; //approved, awaiting_moderation, spam, tot

// Solution 2
$num_comm2 = wp_count_comments( );
$num_comm2 = $num_comm2-&gt;approved; //approved, moderated, spam, total_comments
</pre>
<h3>Output</h3>
<p>The above syntax shows simple how to get the values without including HTML. In another example I show you all results in HTML as a list. Everybody can adjust the format to integrate in their design.</p>
<pre lang="php">
&lt;?php
$num_posts = wp_count_posts( &#039;post&#039; );
$num_posts = $num_posts-&gt;publish; //publish, draft
$num_posts = sprintf( __ngettext( &#039;%s Post&#039;, &#039;%s Posts&#039;, $num_posts ), number_format_i18n( $num_posts ) );

$num_pages = wp_count_posts( &#039;page&#039; );
$num_pages = $num_pages-&gt;publish; //publish
$num_pages = sprintf( __ngettext( &#039;%s Page&#039;, &#039;%s Pages&#039;, $num_pages ), number_format_i18n( $num_pages ) );

$num_cats  = wp_count_terms(&#039;category&#039;);
$num_tags  = wp_count_terms(&#039;post_tag&#039;);

$num_comm  = get_comment_count();
$num_comm  = $num_comm&#091;&#039;approved&#039;&#093;; //approved, awaiting_moderation, spam, total_comments
$num_comm  = sprintf( __ngettext( &#039;%s Categorie&#039;, &#039;%s Categories&#039;, $num_comm ), number_format_i18n( $num_comm ) );
$num_comm2 = wp_count_comments( );
$num_comm2 = $num_comm2-&gt;approved; //approved, moderated, spam, total_comments

echo &#039;&lt;ul&gt;&#039;;
echo &#039;&lt;li&gt;Posts: &#039; . $num_posts . &#039;&lt;/li&gt;&#039;;
echo &#039;&lt;li&gt;Pages: &#039; . $num_pages . &#039;&lt;/li&gt;&#039;;
echo &#039;&lt;li&gt;Categories: &#039; . $num_cats . &#039;&lt;/li&gt;&#039;;
echo &#039;&lt;li&gt;Tags: &#039; . $num_tags . &#039;&lt;/li&gt;&#039;;
echo &#039;&lt;li&gt;Comments: &#039; . $num_comm . &#039;&lt;/li&gt;&#039;;
echo &#039;&lt;li&gt;Comments 2: &#039; . $num_comm2 . &#039;&lt;/li&gt;&#039;;
echo &#039;&lt;/ul&gt;&#039;;
?&gt;
</pre>
<p>You can adjust the design of these lists. You can use classes or IDs. An example is in article &#8222;<a href="http://bueltge.de/summe-der-kommentare-in-wordpress/742/">Total Amount of Comments</a>&#8220; (in german language), where you can see a button with the amount of comments.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/38/show-amount-of-posts-pages-categories-tags-comments-for-wordpress-themes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

