<?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>wantusiak.com &#187; wp_list_pages</title>
	<atom:link href="http://www.wantusiak.com/tag/wp_list_pages/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wantusiak.com</link>
	<description>This is quite personal</description>
	<lastBuildDate>Wed, 28 Sep 2011 20:13:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>WordPress: How to dynamically modify the output of the wp_list_pages</title>
		<link>http://www.wantusiak.com/wordpress/wordpress-modify-wp_list_pages</link>
		<comments>http://www.wantusiak.com/wordpress/wordpress-modify-wp_list_pages#comments</comments>
		<pubDate>Tue, 24 Feb 2009 18:57:27 +0000</pubDate>
		<dc:creator>Maciek</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[wp_list_pages]]></category>

		<guid isPermaLink="false">http://www.wantusiak.com/?p=479</guid>
		<description><![CDATA[Modifying the output of Wordpres&#8217; template tag wp_list_pages I&#8217;ve noticed a lot of traffic to my previous post on this subject: How to style wp_list_pages, which means that there is a lot of interest in this subject. I recommend reading the previous article as it might explain certain things which I am going to write [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Modifying the output of Wordpres&#8217; template tag wp_list_pages</strong></p>
<p>I&#8217;ve noticed a lot of traffic to my previous post on this subject: <a href="http://www.wantusiak.com/wordpress/wordpress-how-to-style-wp_list_pages">How to style wp_list_pages</a>, which means that there is a lot of interest in this subject.<br />
I recommend reading the previous article as it might explain certain things which I am going to write about here.</p>
<p>For the template that I was recently working on, I needed a modified output of the default <strong><a href="http://codex.wordpress.org/Template_Tags/wp_list_pages">&lt;?php wp_list_pages(&#8216;arguments&#8217;); ?&gt; </a></strong> tag, in a way that it would change the link into and anchor. For example, instead of this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;li class=&quot;page_item page-item-1&quot;&gt; 
    &lt;a title=&quot;thisisanexample&quot; href=&quot;http://www.thisisanexample.com&quot;&gt;this is an example&lt;/a&gt;
&lt;/li&gt;</pre></div></div>

<p>into this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;li class=&quot;page_item page-item-1&quot;&gt; 
    &lt;a title=&quot;thisisanexample&quot; href=&quot;#thisisanexample&quot;&gt;this is an example&lt;/a&gt;
&lt;/li&gt;</pre></div></div>

<p><span id="more-479"></span><br />
If you are wondering what are anchors for: these are the shortcuts that take you from one part of a page to another part of the same page.<br />
Here&#8217;s what I had to start with:</p>
<ul>
<li>A number of pages which all had the same parent</li>
<li>The parent&#8217;s ID is 5 (you need to find this number on your own)</li>
<li>They were all only one level deep (it means that these pages didn&#8217;t have any children)</li>
<li>the powerful wp_list_pages() tag</li>
</ul>
<p>So, this is how to do it&#8230;</p>
<ul>
<li>Find your wp_list_pages() tag in the template</li>
<li>Change the &lt;?php wp_list_pages(&#8216;arguments&#8217;); ?&gt; into the following:</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'echo=0&amp;title_li=&amp;child_of=5&amp;depth=1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$pieces</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$my_pages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pieces</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$tmp1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#'</span><span style="color: #339933;">.</span><span style="color: #000088;">$pieces</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$pieces</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmp1</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$j</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000088;">$tmp2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span><span style="color: #000088;">$pieces</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$tmp2</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<ul>
<li>The above code takes the output of wp_list_pages and assigns it to the variable $my_pages</li>
<li>The parameters of wp_list_pages: <strong>echo=0</strong>,so it doesn&#8217;t output to the screen, <strong>title_li=</strong>, so there is no name for the list, <strong>child_of=5</strong>, so we only get pages, who are children of page no. 5, and <strong>depth=1</strong>, so we don&#8217;t include any children of these pages</li>
<li>After that, we need to split (explode) the output into separate parts (array), at each of the &#8221; characters:</li>
</ul>
<p>from:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;li class=&quot;page_item page-item-1&quot;&gt;&lt;a title=&quot;example title&quot; href=&quot;http://www.examplelink.com&quot;&gt;example title&lt;/a&gt;&lt;/li&gt;'</span></pre></div></div>

<p>into:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">pieces<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;li class=&quot;</span>
pieces<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;page_item page-item-1&quot;</span>
pieces<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&gt;&lt;a title=&quot;</span>
pieces<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;example title&quot;</span>
pieces<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot; href=&quot;</span>
pieces<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.examplelink.com&quot;</span>
pieces<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&gt;example title&lt;/a&gt;&lt;/li&gt;&quot;</span></pre></div></div>

<ul>
<li>Next, we find what are we going to use: pages[3] and pages[5] &#8211; the title and the link</li>
<li>Also, if we have more than 1 link, then we need to set a limit of how many times the <strong>for</strong> function will be executed &#8211; we can do it easily by getting the number of elements in the <strong>pieces[]</strong> array:</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pieces</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<ul>
<li>Then, we set up a <strong>for loop</strong> which goes through the whole <strong>pieces[]</strong> array and exchanges every link with its title, preceded with # (the anchor mark):</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$tmp1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#'</span><span style="color: #339933;">.</span><span style="color: #000088;">$pieces</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pieces</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmp1</span><span style="color: #339933;">;</span></pre></div></div>

<ul>
<li>The above creates a temporary variable by joining the &#8216;#&#8217; sign with the title of the link (from pieces[3]), and then changes the value of pieces[5] to that temporary variable, which now is our anchor</li>
<li>And finally, if you have more than one link (page) then you will need to increase both $i and $j values by 6 &#8211; this is how often they are occurring in the pieces[] array</li>
<li>When there are no more pieces left to go through and the for loop ends, we need to join all the values of the pieces[] array back into one single variable and print it out</li>
</ul>
<p>And that is it.</p>
<p>It might happen that the wp_list_pages function outputs the title and the link swapped (link comes before the title), then just swap the values of $i and $j, and it should work.</p>
<p>Oh, and it only works with the unmodified output of the <strong><a href="http://codex.wordpress.org/Template_Tags/wp_list_pages">&lt;?php wp_list_pages(&#8216;arguments&#8217;); ?&gt; </a></strong> tag &#8211; it might behave differently when used together with what I have discussed in the previous link on this subject: <a href="http://www.wantusiak.com/wordpress/wordpress-how-to-style-wp_list_pages">How to style wp_list_pages</a></p>
<p>As usual, let me know what you think about this hack (especially since it isn&#8217;t the only way of doing it) and ask questions in the comments if you need help.</p>
<p>Thanks<br />
If you found this interesting, please also check out this post on <a href="http://www.wantusiak.com/wordpress/wordpress-how-to-style-wp_list_pages">styling wp_list_pages</a></p>
<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wantusiak.com/wordpress/wordpress-modify-wp_list_pages/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WordPress: How to style wp_list_pages</title>
		<link>http://www.wantusiak.com/wordpress/wordpress-how-to-style-wp_list_pages</link>
		<comments>http://www.wantusiak.com/wordpress/wordpress-how-to-style-wp_list_pages#comments</comments>
		<pubDate>Thu, 25 Sep 2008 19:08:54 +0000</pubDate>
		<dc:creator>Maciek</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[wp_list_pages]]></category>

		<guid isPermaLink="false">http://www.wantusiak.com/?p=65</guid>
		<description><![CDATA[Applying styling to dynamically generated lists (or any content) in WordPress. Recently, I was in a need of changing the default outcome of the &#60;?php wp_list_pages(&#8216;arguments&#8217;); ?&#62; tag in WordPress &#8211; as you&#8217;ll see, it&#8217;s a really simple procedure. I needed to change the wp_list_pages outcome, but this technique can be applied to other tags as well. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Applying styling to dynamically generated lists (or any content) in WordPress.</strong><br />
Recently, I was in a need of changing the default outcome of the <strong><a href="http://codex.wordpress.org/Template_Tags/wp_list_pages">&lt;?php wp_list_pages(&#8216;arguments&#8217;); ?&gt; </a></strong>tag in WordPress &#8211; as you&#8217;ll see, it&#8217;s a really simple procedure. I needed to change the wp_list_pages outcome, but this technique can be applied to other tags as well.</p>
<p>On default, after calling this script, we recieve something along these lines:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;ul&gt;
    &lt;li class=&quot;page_item current_page_parent&quot;&gt; 
        &lt;a href=&quot;#&quot;&gt;Link&lt;/a&gt;
    &lt;/li&gt;
    &lt;li class=&quot;page_item&quot;&gt; 
        &lt;a href=&quot;#&quot;&gt;Link2&lt;/a&gt;
    &lt;/li&gt;
&lt;/ul&gt;</pre></div></div>

<p><span id="more-65"></span><br />
On some ocasions you will probably wish to add a <strong>&lt;class&gt;</strong> or a <strong>&lt;span&gt;</strong> to each link. Too bad that the <strong>wp_list_pages()</strong> tag doesn&#8217;t take as arguments strings to go before and after each link.</p>
<p>So, this is the way that you can go around this problem:</p>
<ul>
<li>Find your wp_list_pages() tag in the template</li>
</ul>
<ul>
<li>Change the &lt;?php wp_list_pages(&#8216;arguments&#8217;); ?&gt; into the following:</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'echo=0&amp;title_li='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;a'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;span class=&quot;testClass&quot;&gt;&lt;a'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;/a'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var4</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;/a&gt;&lt;/span&gt;;'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$my_pages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var3</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var4</span><span style="color: #339933;">,</span> <span style="color: #000088;">$my_pages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$my_pages</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<ul>
<li>The above looks for strings <strong>$var1</strong> and <strong>$var3</strong> and changes them with <strong>$var2</strong> and <strong>$var4</strong>, respectively in the <strong>$my_pages</strong> variable (which is the outcome of the <strong>wp_list_pages()</strong> tag)</li>
<li>It is important to pass <strong>echo=0&amp;title_li=</strong> as arguments because the output would be otherwise not stored as the <strong>&amp;my_pages</strong> variable (echo=0) and the list would have a title &#8211; typically &#8220;Pages&#8221; (title_li=)</li>
<li>After this operation the previous code looks like this:</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;ul&gt;
    &lt;li class=&quot;page_item current_page_parent&quot;&gt; 
        &lt;span class=&quot;testClass&quot;&gt;
            &lt;a href=&quot;#&quot;&gt;Link&lt;/a&gt;
        &lt;/span&gt;
    &lt;/li&gt;
    &lt;li class=&quot;page_item&quot;&gt;
        &lt;span class=&quot;testClass&quot;&gt;
            &lt;a href=&quot;#&quot;&gt;Link2&lt;/a&gt;
        &lt;/span&gt;
    &lt;/li&gt;
&lt;/ul&gt;</pre></td></tr></table></div>

<p>And this is it! Simple yet powerful. This litlle trick can have many applications (like, for example, creating a hover effect with some script on the menu) and it is up to you what to do with it next. If you are going to use it for something &#8211; it&#8217;s always appreciated if you could share your ideas.</p>
<p><strong>Update!</strong> I&#8217;ve noticed that a lot of interest is paid to this post. If some of you would like me to explain something in more detail, then ask for it in a comment. I hope that I will be able to help :)<br />
<strong>Update 2!</strong> I have written a new post about modifying the outcome of the wp_list_pages tag &#8211; have a look here: <a href="http://www.wantusiak.com/wordpress/wordpress-modify-wp_list_pages">WordPress: how to dynamically modify the output of the wp_list_pages tag</a><br />
Take care!</p>
<p>Maciek</p>
<p><strong>Q1: How would one style an element inside a link?</strong><br />
Here is a little modification of the script to include styling of parts of a link, as suggested by <a href="http://teamtupper.com/">Ben</a>, although Ben&#8217;s problem was a little more complex.<br />
The problem is how to style one part of a link, for example: The link is &#8220;WordPress Rocks!&#8221; and we want to apply style only to the word &#8220;WordPress&#8221;, to be&#8230; mmmm&#8230;. bold and green! That&#8217;s how to do it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'echo=0&amp;title_li='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;a'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;span class=&quot;testClass&quot;&gt;&lt;a'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;/a'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var4</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;/a&gt;&lt;/span&gt;;'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var5</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Wordpress'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var6</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;h10&gt;Wordpress&lt;/h10&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$my_pages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var3</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var4</span><span style="color: #339933;">,</span> <span style="color: #000088;">$my_pages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var5</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var6</span><span style="color: #339933;">,</span> <span style="color: #000088;">$my_pages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$my_pages</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>As you can see, I have wrapped the word &#8220;WordPress&#8221; in <strong>&lt;h10&gt;</strong> tag. Why not &lt;span&gt;? Because for what I know it creates a bunch of gibberish as outcome (try it and you&#8217;ll know it). &lt;h10&gt;, or any &lt;h&gt; tag which is not being used, is a simpler solution.<br />
Don&#8217;t forget to style it in your CSS file. If the &lt;h&gt; tag breaks your line, use &#8220;<strong>display:inline;</strong>&#8221; in your style sheet to fix it.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">h10 <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> Green<span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Oh, and I am assuming that the word &#8220;WordPress&#8221; is a constant output from the wp_list_pages(). This means, that wp_list_pages() always outputs the word &#8220;WordPress&#8221;.</p>
<p><strong>Q1: How to add a line between to &lt;li&gt; elements?</strong><br />
Here&#8217;s how:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'echo=0&amp;title_li='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/li&gt;&lt;li'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$var2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/li&gt; whatever you want to add here &lt;li'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$my_pages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$my_pages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$my_pages</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>
<p style="color: red;">UPDATED!!! 25.04.2009</p>
<p></strong><br />
<strong>Q2: How do you create a dynamic submenu? </strong><br />
<strong>Marc Wiest</strong> was kind to share wit us a solution to this problem, based on the above hack and work by <a href="http://www.svennerberg.com/2009/02/creating-a-submenu-in-wordpress/">Gabriel Svennerberg</a>.<br />
Here is how to create a dynamic submenu:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>  
    <span style="color: #000088;">$has_subpages</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>  
    <span style="color: #666666; font-style: italic;">// Check to see if the current page has any subpages  </span>
    <span style="color: #000088;">$children</span> <span style="color: #339933;">=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;child_of='</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;echo=0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$children</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
        <span style="color: #000088;">$has_subpages</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span>  
    <span style="color: #666666; font-style: italic;">// Reseting $children  </span>
    <span style="color: #000088;">$children</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>  
    <span style="color: #666666; font-style: italic;">// Fetching the right thing depending on if we're on a subpage or on a parent page (that has subpages)  </span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
        <span style="color: #666666; font-style: italic;">// This is a subpage  </span>
        <span style="color: #000088;">$children</span> <span style="color: #339933;">=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title_li=&amp;include=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;echo=0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
        <span style="color: #000088;">$children</span> <span style="color: #339933;">.=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title_li=&amp;child_of=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;echo=0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$has_subpages</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
        <span style="color: #666666; font-style: italic;">// This is a parent page that have subpages  </span>
        <span style="color: #000088;">$children</span> <span style="color: #339933;">=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title_li=&amp;include=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;echo=0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
        <span style="color: #000088;">$children</span> <span style="color: #339933;">.=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title_li=&amp;child_of=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;echo=0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span>  
<span style="color: #000000; font-weight: bold;">?&gt;</span>  
&lt;!--Check to see if we have anything to output--&gt;  
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$children</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>  
    &lt;div class=&quot;subNav&quot;&gt;
	&lt;ul&gt;
    	    &lt;li&gt;
            &lt;!--modified wp_list_pages--&gt;
	        <span style="color: #000000; font-weight: bold;">&lt;?php</span>
                    <span style="color: #000088;">$var1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;a'</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$var2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;span class=&quot;testClass&quot;&gt;&lt;a'</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$var3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$var4</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;/a&gt;&lt;/span&gt;'</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$children</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$children</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$children</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var3</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var4</span><span style="color: #339933;">,</span> <span style="color: #000088;">$children</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                   <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$children</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">?&gt;</span>
                &lt;!--end of modified wp_list_pages--&gt;
            &lt;/li&gt;
        &lt;/ul&gt;  
    &lt;/div&gt;&lt;!--subNav--&gt;  
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>I didn&#8217;t get a chance to test out this code (but it looks alright to me and it works for Marc), so if you run into any problems, let me know in the comment.<br />
Also you are welcome to share your problems and solutions.<br />
Again, thanks Marc!</p>
<p>If you found this post interesting, have a look at the one about <a href="http://www.wantusiak.com/wordpress/wordpress-modify-wp_list_pages">dynamically modifying the wp_list_pages output</a><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wantusiak.com/wordpress/wordpress-how-to-style-wp_list_pages/feed</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
	</channel>
</rss>

