<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Set a Body Id Using PHP</title>
	<atom:link href="http://trevordavis.net/blog/tutorial/set-a-body-id/feed/" rel="self" type="application/rss+xml" />
	<link>http://trevordavis.net/blog/tutorial/set-a-body-id/</link>
	<description>Doing That Web Standards Thing</description>
	<lastBuildDate>Thu, 11 Mar 2010 20:25:01 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Yoosuf</title>
		<link>http://trevordavis.net/blog/tutorial/set-a-body-id/#comment-3192</link>
		<dc:creator>Yoosuf</dc:creator>
		<pubDate>Sun, 12 Jul 2009 17:05:55 +0000</pubDate>
		<guid isPermaLink="false">http://trevordavis.net/?p=195#comment-3192</guid>
		<description>What do you think about this method?

&lt;pre&gt;&lt;code&gt;post_parent; // test to see if this it a parent
$postID = $post-&gt;ID; // get this post&#039;s ID
$ancestors = get_post_ancestors($post);
$top = end($ancestors);

if($isparent == &#039;0&#039;) { // if there is no parent, grab this page&#039;s name
$getname = get_post($postID);
} else {
$getname = get_post($top);
}
$toplevel = &#039; id=&quot;&#039; . $getname-&gt;post_name . &#039;&quot; class=&quot;page&quot;&#039;;
} else if(is_category()) { // if we&#039;re on a category listing
$cat = get_query_var(&#039;cat&#039;);
$parents = get_category_parents($cat,FALSE,&#039;^&#039;,TRUE);
$get_parent = explode(&#039;^&#039;,$parents);
$toplevel = &#039; id=&quot;&#039; . $get_parent[0] . â€˜â€ class=â€categoryâ€â€˜;
} else if(is_single()) { // if this is a single post page
$toplevel = â€˜ id=â€singleâ€â€˜;
}
echo $toplevel;
} ?&gt;&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>What do you think about this method?</p>
<pre><code>post_parent; // test to see if this it a parent
$postID = $post-&gt;ID; // get this post's ID
$ancestors = get_post_ancestors($post);
$top = end($ancestors);

if($isparent == '0') { // if there is no parent, grab this page's name
$getname = get_post($postID);
} else {
$getname = get_post($top);
}
$toplevel = ' id="' . $getname-&gt;post_name . '" class="page"';
} else if(is_category()) { // if we're on a category listing
$cat = get_query_var('cat');
$parents = get_category_parents($cat,FALSE,'^',TRUE);
$get_parent = explode('^',$parents);
$toplevel = ' id="' . $get_parent[0] . â€˜â€ class=â€categoryâ€â€˜;
} else if(is_single()) { // if this is a single post page
$toplevel = â€˜ id=â€singleâ€â€˜;
}
echo $toplevel;
} ?&gt;</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Teddy</title>
		<link>http://trevordavis.net/blog/tutorial/set-a-body-id/#comment-2341</link>
		<dc:creator>Teddy</dc:creator>
		<pubDate>Thu, 12 Feb 2009 02:52:11 +0000</pubDate>
		<guid isPermaLink="false">http://trevordavis.net/?p=195#comment-2341</guid>
		<description>BodyId&#039;s  &amp;   are MUSTS for serious site developers with growing content, especially if your content is driven by a database.

For those that don&#039;t like  or  you can change the following for a cleaner look:


&lt;a href=&quot;#&quot; rel=&quot;nofollow&quot;&gt;Home&lt;/a&gt;
&lt;a href=&quot;#&quot; rel=&quot;nofollow&quot;&gt;About&lt;/a&gt;


The CSS will change a little too:

&lt;pre&gt;&lt;code&gt;body#home #nav #home a { styles... }
body#about #nav #about a {styles... }

.subnav { ...
.subnav a:link { ...
.subnav a:hover { ...&lt;/code&gt;&lt;/pre&gt;

//just a note for the newbs like me</description>
		<content:encoded><![CDATA[<p>BodyId&#8217;s  &amp;   are MUSTS for serious site developers with growing content, especially if your content is driven by a database.</p>
<p>For those that don&#8217;t like  or  you can change the following for a cleaner look:</p>
<p><a href="#" rel="nofollow">Home</a><br />
<a href="#" rel="nofollow">About</a></p>
<p>The CSS will change a little too:</p>
<pre><code>body#home #nav #home a { styles... }
body#about #nav #about a {styles... }

.subnav { ...
.subnav a:link { ...
.subnav a:hover { ...</code></pre>
<p>//just a note for the newbs like me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevor</title>
		<link>http://trevordavis.net/blog/tutorial/set-a-body-id/#comment-2214</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Mon, 26 Jan 2009 05:13:02 +0000</pubDate>
		<guid isPermaLink="false">http://trevordavis.net/?p=195#comment-2214</guid>
		<description>@Dan-
Without looking at the actual ASP, I am assuming that it may be just checking the URL to decide what to do with the navigation.

You should be able to examine the URL and use conditionals to determine what to do.

Hopefully that should help.</description>
		<content:encoded><![CDATA[<p>@Dan-<br />
Without looking at the actual ASP, I am assuming that it may be just checking the URL to decide what to do with the navigation.</p>
<p>You should be able to examine the URL and use conditionals to determine what to do.</p>
<p>Hopefully that should help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://trevordavis.net/blog/tutorial/set-a-body-id/#comment-2211</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Sun, 25 Jan 2009 16:43:40 +0000</pubDate>
		<guid isPermaLink="false">http://trevordavis.net/?p=195#comment-2211</guid>
		<description>Hi Trevor,
I migrated this asp site over to php because of my web server.
the navigation on the left uses conditional asp statement to change the css link behaviour depending on the page you are on.
could you help me implement the php code?

you can view the two behaviours on the original site:
http://www.toolgal.com/chain.asp
and the migrated site:
http://www.dmdesign.co.il/toolgal/chain.php


I would be glad to send you the source codes if needed.

Thanks,
Dan</description>
		<content:encoded><![CDATA[<p>Hi Trevor,<br />
I migrated this asp site over to php because of my web server.<br />
the navigation on the left uses conditional asp statement to change the css link behaviour depending on the page you are on.<br />
could you help me implement the php code?</p>
<p>you can view the two behaviours on the original site:<br />
<a href="http://www.toolgal.com/chain.asp" rel="nofollow">http://www.toolgal.com/chain.asp</a><br />
and the migrated site:<br />
<a href="http://www.dmdesign.co.il/toolgal/chain.php" rel="nofollow">http://www.dmdesign.co.il/toolgal/chain.php</a></p>
<p>I would be glad to send you the source codes if needed.</p>
<p>Thanks,<br />
Dan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dan</title>
		<link>http://trevordavis.net/blog/tutorial/set-a-body-id/#comment-2201</link>
		<dc:creator>dan</dc:creator>
		<pubDate>Sat, 24 Jan 2009 12:59:26 +0000</pubDate>
		<guid isPermaLink="false">http://trevordavis.net/?p=195#comment-2201</guid>
		<description>thanks! great implementation! just what i needed.</description>
		<content:encoded><![CDATA[<p>thanks! great implementation! just what i needed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darcy</title>
		<link>http://trevordavis.net/blog/tutorial/set-a-body-id/#comment-1941</link>
		<dc:creator>Darcy</dc:creator>
		<pubDate>Sat, 22 Nov 2008 00:37:05 +0000</pubDate>
		<guid isPermaLink="false">http://trevordavis.net/?p=195#comment-1941</guid>
		<description>@Ozh, I implemented this on a Wordpress site we just built and it worked fine. I did take into account what Mark said and use preg_match instead. It worked great and even does away with the true/false check, it looks something like this:

&lt;pre&gt;&lt;code&gt;function setBodyId() {
    	$path = $_SERVER[&#039;REQUEST_URI&#039;];
	if(!isset($bodyId)) {
		if (preg_match(&#039;/about/i&#039;,$path)) {
			$bodyId = &#039;about&#039;;
		} else if (preg_match(&#039;/contact/i&#039;,$path)) {
			$bodyId = &#039;contact&#039;;
		} else if (preg_match(&#039;/services/i&#039;,$path)) {
			$bodyId = &#039;services&#039;;
		} else if (preg_match(&#039;//i&#039;,$path)) {
			$bodyId = &#039;home&#039;;
        	} else {
                	$bodyId = &#039;general&#039;;
        	}
        }
    return $bodyId;
}
$bodyId = setBodyId();&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@Ozh, I implemented this on a Wordpress site we just built and it worked fine. I did take into account what Mark said and use preg_match instead. It worked great and even does away with the true/false check, it looks something like this:</p>
<pre><code>function setBodyId() {
    	$path = $_SERVER['REQUEST_URI'];
	if(!isset($bodyId)) {
		if (preg_match('/about/i',$path)) {
			$bodyId = 'about';
		} else if (preg_match('/contact/i',$path)) {
			$bodyId = 'contact';
		} else if (preg_match('/services/i',$path)) {
			$bodyId = 'services';
		} else if (preg_match('//i',$path)) {
			$bodyId = 'home';
        	} else {
                	$bodyId = 'general';
        	}
        }
    return $bodyId;
}
$bodyId = setBodyId();</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Links of Interest - CSS-Tricks</title>
		<link>http://trevordavis.net/blog/tutorial/set-a-body-id/#comment-804</link>
		<dc:creator>Links of Interest - CSS-Tricks</dc:creator>
		<pubDate>Wed, 14 May 2008 12:45:43 +0000</pubDate>
		<guid isPermaLink="false">http://trevordavis.net/?p=195#comment-804</guid>
		<description>[...] ID about a million times here on CSS-Tricks, so I figured this was highly appropriate. Trevor Davis shares his technique on how he sets this using PHP. Basically it analyzes the URL to see what sub-directory you are in [...]</description>
		<content:encoded><![CDATA[<p>[...] ID about a million times here on CSS-Tricks, so I figured this was highly appropriate. Trevor Davis shares his technique on how he sets this using PHP. Basically it analyzes the URL to see what sub-directory you are in [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ozh</title>
		<link>http://trevordavis.net/blog/tutorial/set-a-body-id/#comment-783</link>
		<dc:creator>Ozh</dc:creator>
		<pubDate>Sat, 10 May 2008 12:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://trevordavis.net/?p=195#comment-783</guid>
		<description>Yet another code snippet killed by WP :)
If you&#039;re posting code, consider using plugins such as iG Syntax Hiliter. Otherwise, all we get is curly quotes that crash code :)</description>
		<content:encoded><![CDATA[<p>Yet another code snippet killed by WP :)<br />
If you&#8217;re posting code, consider using plugins such as iG Syntax Hiliter. Otherwise, all we get is curly quotes that crash code :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevor</title>
		<link>http://trevordavis.net/blog/tutorial/set-a-body-id/#comment-778</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Fri, 09 May 2008 17:36:13 +0000</pubDate>
		<guid isPermaLink="false">http://trevordavis.net/?p=195#comment-778</guid>
		<description>@Mark-
Nice, thanks for the PHP tips.</description>
		<content:encoded><![CDATA[<p>@Mark-<br />
Nice, thanks for the PHP tips.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark James</title>
		<link>http://trevordavis.net/blog/tutorial/set-a-body-id/#comment-777</link>
		<dc:creator>Mark James</dc:creator>
		<pubDate>Fri, 09 May 2008 08:23:39 +0000</pubDate>
		<guid isPermaLink="false">http://trevordavis.net/?p=195#comment-777</guid>
		<description>Body IDs can be absolute lifesavers, I&#039;ll certainly attest to that.

Just a few notes on the PHP sideâ€¦

You could get away with just using stripos checks against the URI rather than ereg. If you do feel the need to use regular expressions (i.e. for more complicated URI-matching), then you&#039;d do well to replace eregi with the pcre-compatible preg_match function (see http://php.net/pcre), which is faster and not prone to being discontinued any time soon (ereg will not be in the PHP core as of PHP6).</description>
		<content:encoded><![CDATA[<p>Body IDs can be absolute lifesavers, I&#8217;ll certainly attest to that.</p>
<p>Just a few notes on the PHP sideâ€¦</p>
<p>You could get away with just using stripos checks against the URI rather than ereg. If you do feel the need to use regular expressions (i.e. for more complicated URI-matching), then you&#8217;d do well to replace eregi with the pcre-compatible preg_match function (see <a href="http://php.net/pcre)" rel="nofollow">http://php.net/pcre)</a>, which is faster and not prone to being discontinued any time soon (ereg will not be in the PHP core as of PHP6).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
