<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<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"
		>
	<channel>
		<title>bbPress Support Forums &#187; Topic: Functions for generating a menu of WordPress pages</title>
		<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages</link>
		<description>bbPress Support Forums &#187; Topic: Functions for generating a menu of WordPress pages</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 11:19:03 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
				<atom:link href="http://bbpress.org/forums/rss/topic/functions-for-generating-a-menu-of-wordpress-pages" rel="self" type="application/rss+xml" />

		<item>
			<title>Thorned Rose on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-74464</link>
			<pubDate>Wed, 29 Sep 2010 23:33:50 +0000</pubDate>
			<dc:creator>Thorned Rose</dc:creator>
			<guid isPermaLink="false">74464@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>I had my husband look at it, who's far more php savvy than I am and while we were able to make some headway and get it partially working thanks to what you provided Mr Pelle. However, we realised it was a lot of work to get it working with WP3 so I ended up going with Pixopoint Theme Generator to spit out the html for the menu and then made a cufon mini-plugin for the custom font. Far less styley but a lot faster and well at this point, at least it works lol.
</p>]]></description>
					</item>
		<item>
			<title>mr_pelle on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-74174</link>
			<pubDate>Wed, 22 Sep 2010 10:53:32 +0000</pubDate>
			<dc:creator>mr_pelle</dc:creator>
			<guid isPermaLink="false">74174@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>The code above has some errors in it: <code>$thisPage</code> is used when calling <code>bb_list_pages()</code> recursively, but this param isn't defined anywhere but in the function's description... =P In function definition that param is instead named <code>$parent_uri</code>.</p>
<p>Moreover <code>$kids &#60;&#62; &#34;&#34;</code> should be replaced by <code>!empty($kids)</code> and I'm not sure that <code>wordpress_mu_primary_blog_id</code> has any meaning now that WP 3.0 has merged WP and WPMU...</p>
<p>Last, calling <code>bb_list_pages()</code> with no args, makes <code>if ($depth == 0)</code> true, resulting in an empty string returned. It would be good to use the same template of <code>wp_list_pages()</code>, which lists <strong>all</strong> pages if no param is passed to it (see <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages">docs</a>). By the way, this could be the reason why you get nothing displayed when calling the function.
</p>]]></description>
					</item>
		<item>
			<title>Thorned Rose on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-74169</link>
			<pubDate>Wed, 22 Sep 2010 04:43:43 +0000</pubDate>
			<dc:creator>Thorned Rose</dc:creator>
			<guid isPermaLink="false">74169@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>Does anyone know if this still works with the current incarnations of wordpress and bbpress? I've tried it but it comes up with nada (using the default bbpress template with &#60;?php echo bb_list_pages();?&#62; added).
</p>]]></description>
					</item>
		<item>
			<title>talatorre on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-64591</link>
			<pubDate>Sun, 14 Feb 2010 07:48:12 +0000</pubDate>
			<dc:creator>talatorre</dc:creator>
			<guid isPermaLink="false">64591@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>One other note, unlike wp_list_pages()  you need to call this function with echo:</p>
<p>     &#60;?php echo bb_list_pages();?&#62;</p>
<p> or modify the last few lines of the function from:</p>
<p>     // Return the string to the caller<br />
     return $output;</p>
<p>to:</p>
<p>     // Return the string to the caller<br />
     echo $output;<br />
     return;</p>
<p>then you can call the function similar to wp_list_pages()</p>
<p>     &#60;?php bb_list_pages();?&#62;
</p>]]></description>
					</item>
		<item>
			<title>talatorre on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-64590</link>
			<pubDate>Sun, 14 Feb 2010 06:38:20 +0000</pubDate>
			<dc:creator>talatorre</dc:creator>
			<guid isPermaLink="false">64590@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>aprendedor</p>
<p>This is how I understand the code:</p>
<p>function pages_table() {<br />
		global $bb;  //calls global variable</p>
<p>		// Compute the name of the table we need to query<br />
		$table = $bb-&#62;wp_table_prefix; //this calls the wp prefix from the wordpress integration settings, ex: wp_<br />
		if ($bb-&#62;wordpress_mu_primary_blog_id != "")  //checks for a WPMU id in the WP integration settings<br />
			$table .= $bb-&#62;wordpress_mu_primary_blog_id."_";  //appends the id, ex: wp_1<br />
		$table .= "posts"; //appends "posts", ex: wp_posts or wp_1posts<br />
		return $table;<br />
	}</p>
<p>To answer your questions the code works no matter which type of WP flavor you are using
</p>]]></description>
					</item>
		<item>
			<title>aprendedor on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-55978</link>
			<pubDate>Wed, 05 Aug 2009 00:15:59 +0000</pubDate>
			<dc:creator>aprendedor</dc:creator>
			<guid isPermaLink="false">55978@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>So.. is there a BBpres and WordPress integration in the site:<br />
<a href="http://granadagazette.com" rel="nofollow">http://granadagazette.com</a>
</p>]]></description>
					</item>
		<item>
			<title>aprendedor on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-55660</link>
			<pubDate>Thu, 30 Jul 2009 14:31:01 +0000</pubDate>
			<dc:creator>aprendedor</dc:creator>
			<guid isPermaLink="false">55660@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>Hello chrishajer,<br />
I am running WordPress 2.8.2 and BBPress 1.0. I have put it into a file called functions.php in the kakumei dir. because I am using the kakumei theme.<br />
I noticed that the new functions file is address to wordpress mu. and I am not running wordpres mu. what should I do now. what code should I put in the header to call that functions to deliver the header. I know also that I neeed to change "wordpress_mu_primary_blog_id" to some that call the regular wordpress  but what itis?</p>
<p>THANK U for sparing some time and help with me!
</p>]]></description>
					</item>
		<item>
			<title>chrishajer on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-55658</link>
			<pubDate>Thu, 30 Jul 2009 12:57:32 +0000</pubDate>
			<dc:creator>chrishajer</dc:creator>
			<guid isPermaLink="false">55658@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>If you are using 1.0, create a file called functions.php in your current theme directory, and put all that code into it.</p>
<p>If you're using less than 1.0, you can create a plugin from that code.  Just add a plugin header to the top of all that, like this:</p>
<pre><code>&#60;?php
/*
Plugin Name: WordPress pages for bbPress
*/
?&#62;</code></pre>
<p>And put it into file called something like <code>wordpress-pages.php</code> and drop that into folder called <code>my-plugins</code> at the same level as <code>bb-plugins</code>.  If the folder is not there, you can create it.  After it's in the folder, log into the admin, you should see it there, then activate it.  And report back how it worked for you.</p>
<p>Thanks
</p>]]></description>
					</item>
		<item>
			<title>aprendedor on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-55651</link>
			<pubDate>Thu, 30 Jul 2009 08:23:56 +0000</pubDate>
			<dc:creator>aprendedor</dc:creator>
			<guid isPermaLink="false">55651@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>where will you put this file. and how would you link it to the theme? I would love to try it  but I am not sure how to address it.
</p>]]></description>
					</item>
		<item>
			<title>chrishajer on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-55644</link>
			<pubDate>Thu, 30 Jul 2009 05:19:08 +0000</pubDate>
			<dc:creator>chrishajer</dc:creator>
			<guid isPermaLink="false">55644@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>I would think that would be useful as a plugin for people wanting to integrate their WordPress page navigation into bbPress.  has anyone tried it out?
</p>]]></description>
					</item>
		<item>
			<title>TonyVitabile on "Functions for generating a menu of WordPress pages"</title>
			<link>http://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages#post-55598</link>
			<pubDate>Wed, 29 Jul 2009 15:51:22 +0000</pubDate>
			<dc:creator>TonyVitabile</dc:creator>
			<guid isPermaLink="false">55598@http://bbpress.org/forums/</guid>
			<description><![CDATA[<p>OK, here's the functions.php file that I created in my theme to reproduce the drop down menu I had on my WordPress side.  </p>
<p>Please note that this code does <strong>not</strong> attempt to reproduce all of the functionality of the WordPress wp_list_pages() function.  Rather, it just tries to create the HTML needed for the drop down menu code that came with my WordPress theme to work.  If you need anything more than that, feel free to modify this or strike out on your own.</p>
<p><strong>Overview</strong><br />
Before the code, just a quick overview of how it works.</p>
<p>The function bb_list_pages() is a recursive function that returns a string containing the HTML for all of the pages that descend from a particular ancestor.  The process is started by calling it with a parent ID of 0.  The way the wp_posts table in WP is designed, this returns the highest level.</p>
<p>The function calls a helper function called get_pages() to retrieve the list of child pages from the database.  It then loops through all of the pages returned by get_pages() &#38; constructs the list item &#38; anchor tags.  It then calls itself to build the HTML for any descendants of the current page.</p>
<p>Here's the code:</p>
<pre><code>&#60;?php
	/**
	 * This file contains useful functions that can be called in any of the template&#39;s files.
	 *
	 * Version 1.0
	 * Date: 23-July-2009
	 * Author:  Tony Vitabile
	 */

	function curPageURL() {
		$pageURL = &#39;http&#39;;
		if ($_SERVER[&#34;HTTPS&#34;] == &#34;on&#34;) {$pageURL .= &#34;s&#34;;}
		$pageURL .= &#34;://&#34;.$_SERVER[&#34;SERVER_NAME&#34;];
		if ($_SERVER[&#34;SERVER_PORT&#34;] != &#34;80&#34;) {
			$pageURL .= &#34;:&#34;.$_SERVER[&#34;SERVER_PORT&#34;];
		}
		$pageURL .= $_SERVER[&#34;REQUEST_URI&#34;];

		return $pageURL;
	}

	/**
	 * Compute the name of the WordPress pages table &#38; return it
	 */
	function pages_table() {
		global $bb;

		// Compute the name of the table we need to query
		$table = $bb-&#62;wp_table_prefix;
		if ($bb-&#62;wordpress_mu_primary_blog_id != &#34;&#34;)
			$table .= $bb-&#62;wordpress_mu_primary_blog_id.&#34;_&#34;;
		$table .= &#34;posts&#34;;
		return $table;
	}

	/**
	 * Retrieve a list of pages from the WordPress posts table whose parent has the ID
	 * passed to this function.
	 *
	 * @param int $parent ID of the page that is the parent of the ones we&#39;re searching for
	 * @return array List of pages matching defaults or $args
	 */
	function get_pages($parent = 0) {
		global $bbdb;

		// Compute the name of the table we need to query
		$table = pages_table();

		// Build our query string
		$parent = (int) $parent;
		$query = &#34;SELECT * FROM {$table} WHERE post_type = &#39;page&#39; AND post_status = &#39;publish&#39; AND post_parent = {$parent} ORDER BY menu_order&#34;;

		// Get an array of rows back from the database
		$pages = $bbdb-&#62;get_results($query);

		// Return whatever we got back to the caller
		return $pages;
	}

	/**
	 * Simple function to recursively scan the WordPress posts table looking for pages.
	 * It builds a string consisting of &#60;ul&#62;&#60;li&#62;&#60;/li&#62;...&#60;/ul&#62; items.
	 *
	 * @param int $parent ID of the parent page.  0 = no parent
	 * @param int $depth  How far down in the heirarchy to go
	 * @param string $thisPage The name of the page that is currently being displayed
	 * @returns string A &#60;ul&#62;&#60;li&#62;&#60;/li&#62;...&#60;/ul&#62; list of page navigation information
	 */

	function bb_list_pages($parent = 0, $depth=0, $parent_uri=&#39;&#39;, $indent=&#39;    &#39;) {
		// Initialize the output of the function
		$output = &#34;&#34;;

		// Is the depth = 0?
		if ($depth == 0) {
			// It is.  Return the empty string now
			return $output;
		}

		// Get the child rows of $parent
		$pages = get_pages($parent);

		// Did we get any pages back?
		if ( empty($pages) ) {
			// No, we didn&#39;t.  Return the empty string now
			return $output;
		}

		// Yes, we got pages back.  Loop through all of the pages in our results
		foreach ( $pages as $page ) {
			// Compute this page&#39;s URI
			$page_uri = $parent_uri;
			if (substr($page_uri, -1) != &#39;/&#39;)
				$page_uri .= &#34;/&#34;;
			$page_uri .= $page-&#62;post_name . &#34;/&#34;;

			// Build the &#60;li&#62; tag
			$output .= &#34;{$indent}&#60;li class=\&#34;page_item page-item-{$page-&#62;ID}&#34;;
			if ($page_uri == curPageURL() ) {
				$output .= &#34; current_page_item&#34;;
			}
			$output .= &#34;\&#34;&#62;&#34;;

			// Now build the rest of this item&#39;s information
			$output .= &#34;&#60;a href=\&#34;{$page_uri}\&#34;&#62;&#34;.$page-&#62;post_title.&#34;&#60;/a&#62;\n&#34;;

			if ($page-&#62;ID &#62; 0) {
				// Get this page&#39;s children recursively
				$kids = bb_list_pages($page-&#62;ID, $depth -1, $page_uri, &#39;&#39;, $thisPage, $indent . &#34;  &#34;);

				// Does this page have any children?
				if ($kids &#60;&#62; &#34;&#34;) {
					// It does.  Add the information for the kids surrounded by &#60;ul&#62;&#60;/ul&#62; tages
					$output .= &#34;{$indent}&#60;ul&#62;\n&#34; . $kids . &#34;{$indent}&#60;/ul&#62;\n&#34;;
				}
			}

			// Output the closing &#60;/li&#62;
			$output .= &#34;&#60;/li&#62;&#34;;
		}

		// Return the string to the caller
		return $output;
	}

?&#62;</code></pre>
<p>Tony
</p>]]></description>
					</item>

	</channel>
</rss>

