Pre-Alpha 1.0
MB Montessori

tenterhooks

suspense seldom kills

Archive for the ‘WP Support’ Category

Site Closed

Monday, May 12th, 2008

I have revived this site in a static format - no new posts and no new comments. All my work will be posted on my main site: www.webdezine.ca . I apologize to anyone that attempted to access the site over the last 6+ months, but I abruptly returned to school which has gobbled up all of my free time. I will be around my webdezine site attempting to update the menu to work with Wordpress 2.3-2.5.

Thanks for all your support in the past :)

Best,
Sheri

wp_list_pages, include parameter?

Thursday, March 8th, 2007

This came from a post on Wordpress Support where the member was looking to lessen his workload by ‘including’ the pages he wanted to display rather than excluding them. As he posts new pages regularly he had to constantly update the pages to ‘exclude’ in his sidebar navigation. Here is the post:

Posted by falp on 03/08/07 :

Hello,
 
This is my first website with wordpress so please excuse if my question is obvious.
 
I want to create a navigation menu on the sidebar using wp_list_pages funtion, but instead of excluding certain pages I want to INCLUDE only certain pages. Is this possible?
 
The reason for this is that as I add more pages to the site I constantly need to update my sidebar.php to exclude the new page ids.
 
I thought of the possibility of creating a static menu linking directly to the pages in question, but then I loose the current_page_item class that is otherwise automatically added.
 
Any pointers would be of great help.
 
Thanks in advance,
 
Frank

In response to Frank’s query, Otto42 came up with a little known parameter that can be used in the ‘wp_list_pages’: the ‘include’ parameter.

Posted by Otto42 on 03/08/07 :

Though it's not documented well, wp_list_pages() appears to support the "include" parameter. So you can do something like this:
wp_list_pages('include=4,8,15,16,23,42');
To show only those pages. Not entirely sure how that would work, mind you, so the results may be unusual. Or they may not. Hard to say.

This does work! but I like to keep on my toes and this seemed like a simple little thing to accomplish, so I took a stab at it.

A little function from me:

<?php
function get_the_pa_ges (){
global $wpdb;
if ( ! $these_pages = wp_cache_get('these_pages', 'pages') ) {
        $these_pages = $wpdb->get_results('select ID, post_title from '. $wpdb->posts .' where post_status = "publish" and post_type = "page" order by ID');
         wp_cache_add('these_pages', $these_pages, 'pages');
   }
  return $these_pages;
}
function list_certain_pages($page_ids=''){
$page_ids = explode(',',$page_ids);
$output = '';
$these_pages = get_the_pa_ges ();
foreach ($these_pages as $thats_them){
$the_page_id = $thats_them->ID;
if (isset($page_ids) && in_array($the_page_id,$page_ids)){
$output .= '<a href="'.get_permalink($thats_them->ID).'" title="'.$thats_them->post_title.'">'.$thats_them->post_title.'</a><br/>';
}
}
return $output;
}
echo list_certain_pages('2,10,89');
?>

This also works. I included a call the database that can be cached. And if someone were to already have my wordpress menu installed, you could use the already cached function called ‘get_pa_ge ()’ to load up the page array needed to create this little side menu by replacing this line :
‘$these_pages = get_the_pa_ges ();’ with ‘$these_pages = get_pa_ge ();’.

As I gaze into my crystal ball, I can tell what you are thinking: “If Wordpress natively supports ‘inclusion’ in the function….why use your function?”. And the answer from beyond this realm is quite simple. Page Load Time. The wp_list_pages function parses at least 183 lines of code through the various functions required to produce the list while my function uses 21 lines.

Tags: , , , ,

Masking Categories in Main Page

Saturday, February 24th, 2007

This post is a reiteration of a thread over atWordpress Support. I am placing it here for posterity :-P

Posted by SubjectEgo on 02/23/07 :

I have need for a setup that will display posts from a specific category "Announcements" on the main page, and mask all others. Other posts must still be accessible through direct linking and through the sidebar. I have not been able to develop a fix for the current setup. Is there a straightforward solution to this?

After carefully scanning the Wordpress Source Cross Reference I came up with a

(more…)

Tags: , ,