Welcome, guest!

Feel free to read the blog, browse for themes, or join the club.

Possibility of adding description to your widgets reoladed wp_list_pages

  1. Hi,
    I know there are a couple of plugins out there which already do the function of adding page descriptions to wp_list_pages for instance your list_child_pages one and also the one add-wordpress-menu-description The latter works on filtering wp_list_pages but I find it too bulky as it adds a special write panel to edit pages, would it be beyond the scope to ask for something similar to be added to either the widgets reloaded or the version that comes built into Hybrid something along the lines of when listing pages, it checks to see if there are any custom fields and if so adds them... Or maybe just give us an idea on how we could filter the wp_list_pages ourselves

    adding the page description and a special rel tag something like:

    page that we want to have special description underneath it has custom fields of

    menudesc this is my shortpage description
    reltag my special rel tag

    add_filter('wp_list_pages', 'descrip_page_lists');
    
    function descrip_page_lists($output) {	
    
    if (page has custom field 'menudesc'){
    $menudesc = Cantquiteworkouthowtogetcustomfielddatahere }
    if (page has custom field 'reltag'){
    $reltag = Cantquiteworkouthowtogetcustomfielddatahere }
    
    $post_title = wptexturize($post_title);
    $output = str_replace('>' . $post_title , 'rel='.$reltag'>' . $post_title . '<span class="mypagedescription">' . $menudesc . '</span>', $output);
    		}
    	}
    	return $output;
    }

    You know that I am always a good source of making you giggle with my hilariously bad PHP skills, but this is the possible way I could think of doing it just wondering how to write it correctly....

    thanks

  2. You must be a logged-in exclusive member to view this reply.

  3. Ok one of the reasons why, I was asking for this, I now understand its outside the scope of the Widgets reloaded. Is that the child theme that I am working on atm (hoping to release it soon), requires by design to have the pages listed in the top menu to have visible page descriptions and It is too far out of scope (currently hard-coded) to ask users to re-hardcode themselves.

    Also, another reason but I do not want to speak about it here, will give you an email (if I may) in regards to that

    thanks, still kinda stuck to get my head around a custom function though,

  4. Ok after banging head against the wall found a solution from Themeshaper

    Now all I have to do is workout how to pass the titles and descriptions through the translator currently getting

    <a href="url">engtitle_fi_title</a>
    <span style="display:block;">engdescription_fidescription</span>
    function sub_page_list() {
     global $wpdb;
     $sql = "SELECT p.ID, p.post_title, p.guid, pm.meta_value FROM " . $wpdb->posts . " AS p LEFT JOIN ";
    $sql .= "(SELECT post_id, meta_value FROM " . $wpdb->postmeta . " AS ipm WHERE meta_key = 'subtitle') ";
    $sql .= "AS pm ON p.ID = pm.post_id ";
    $sql .= "WHERE p.post_type = 'page' AND p.post_parent = 0 AND p.post_status = 'publish' ";
    $sql .= "ORDER BY p.menu_order ASC ";
    $sql .= "LIMIT 0, 10";
    $rows = $wpdb->get_results($sql,OBJECT);
    if($rows) {
     foreach($rows as $row) {
     echo "<li>";
    
    $link_url = get_permalink($row->ID);
     echo "<a href=\"$link_url\"" . "\">$row->post_title</a>";
    echo "<span style=\"display:block;\">$row->meta_value</span>";
    echo "</li>";
    }
     }
     }
    // Filter the menu to add the list
    function childtheme_page_menu() { ?>
    <div class="menu">
     <ul>
    <?php if (is_front_page()) { ?>
     <li><a href="<?php bloginfo('home') ?>/" title="<?php echo wp_specialchars( get_bloginfo('name'), 1 ) ?>" rel="home">
    Home <span style="display:block;">This is the home page</span>
    </a></li>
    <li><a href="<?php bloginfo('home') ?>/" title="<?php echo wp_specialchars( get_bloginfo('name'), 1 ) ?>" rel="home">
     Home <span style="display:block;">Return to the home page</span>
    </a></li>
     <?php } ?>
     <?php sub_page_list(); ?>
    </ul>
    </div>
     <?php }
     add_filter('wp_page_menu','childtheme_page_menu');

    But getting there at least, thanks to Themeshaper

  5. tying myself in knots here... also have to be able to add in current_page for the li tags

  6. You must be a logged-in exclusive member to view this reply.

  7. Ok well, I made some changes, as the ul class wasn't being closed and removed the home from the second one. Now I am having problems changing the args for the wp_page_menu_args

    it is still throwing back all the pages, I cannot choose what pages it shows?

    add_filter( 'wp_page_menu_args', 'custom_page_nav',1 );
    add_filter( 'wp_page_menu', 'childtheme_page_menu' );
    
    function custom_page_nav($args) {
    
    	$args['depth'] = 1;
    	$args['include'] = '167,4,2';
    
    	return $args;
    }
    
    function sub_page_list() {
    	global $wpdb;
    
    	$sql = "SELECT p.ID, p.post_title, p.guid, pm.meta_value FROM " . $wpdb->posts . " AS p LEFT JOIN ";
    	$sql .= "(SELECT post_id, meta_value FROM " . $wpdb->postmeta . " AS ipm WHERE meta_key = 'menu_title') ";
    	$sql .= "AS pm ON p.ID = pm.post_id ";
    	$sql .= "WHERE p.post_type = 'page' AND p.post_parent = 0 AND p.post_status = 'publish' ";
    	$sql .= "ORDER BY p.menu_order ASC ";
    	$sql .= "LIMIT 0, 5";
    
    	$rows = $wpdb->get_results( $sql, OBJECT );
    
    	if ( $rows )
    		foreach ( $rows as $row )
    			echo '<li class="page_item'. ( ( is_page( $row->ID ) ) ? ' current_page_item' : '' ). '"><a  href="' . get_permalink( $row->ID ) . '" title="' . __( $row->post_title ) . '">' . __($row->post_title) . '</a> <p class="page-text">' . __($row->meta_value) . '</p></li>';
    }
    
    function childtheme_page_menu() { ?>
    	<div id="page-nav">
    		<ul>
    <?php sub_page_list(); ?>
    		</ul>
    	</div>
    <?php }

    any help gratefully received

    thanks

    Edit: getting tired here, just reaslised why its not allowing me to change the args it because I am already filtering the menu... doh!

  8. You must be a logged-in exclusive member to view this reply.

  9. Ok, in well over my head now...,

    Just wondering how I would pull in those custom $args to the function..

    going to head off to bed and will try going over this again tomorrow,

    Thanks for your time

  10. You must be a logged-in exclusive member to view this reply.

  11. Ok, it spits out an error when doing

    $sql .= "WHERE p.post_type = 'page' AND p.ID = $args['include'] AND p.post_parent = 0 AND p.post_status = 'publish' ";

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in

    if I change it to (just stabbing in the dark)

    $sql .= "WHERE p.post_type = 'page' AND p.ID = '167,4,2,153,3' AND p.post_parent = 0 AND p.post_status = 'publish' ";

    it only spits out one of the pages, I really am going to sleep now, thanks for all your help

  12. Cracked it!!!

    Sure that this is like killing an ant with a grenade... And probably has some holes, if anybody sees that this could be cleaned up, its always welcome

    // code stripped down version of stuffbysarah.net/wordpress-plugins/page-menu-editor/
    //edited version by fb
    
    add_filter('wp_list_pages','menu_filter', 1);
    add_filter( 'wp_page_menu_args', 'custom_page_nav',100 );
    
    /*wp_list_pages() filter */
    function menu_filter_callback($matches) {
    	global $wpdb;
    
    	if ($matches[1] && !empty($matches[1])) $postID = $matches[1];
    
    	if (empty($postID)) $postID = get_option("page_on_front");
    
    	// now identifies the post ID
    	$menu_title = stripslashes(get_post_meta($postID, 'menu_title', true));
    
    	if (empty($menulabel)) $menulabel = $matches[4];
            if (!empty($menu_title));
    		$filtered = '<li class="page_item page-item-'.$postID.$matches[2].'"><a href="'.$matches[3].'" title="'.$menulabel.'">'.$menulabel.'</a><p class="page-text">'.__($menu_title).'</p>';
    return $filtered;
    }
    
    function menu_filter($content) {
    	$url = preg_replace(array('/\//', '/\./', '/\-/'), array('\/', '\.', '\-'), get_option('siteurl'));
    	$pattern = '@<li class="page_item page-item-(\d+)([^\"]*)"><a href=\"([^\"]+)" title="([^\"]+)">(.*?)</a>@is';
    	return preg_replace_callback($pattern, "menu_filter_callback", $content);
    }
    
    function custom_page_nav($args) {
            $args['depth'] = 1;
    	$args['include'] = '167,4,2,153,3,27';
    	$args['show_home'] = false;
             return $args;
    }

    phew!!
    Now I get to have the page menu just as I required,
    I didn't feel to easy with the previous code,
    Justin if you don't feel comfortable with custom select queries I get on with them as much as my mother-in-law... if you get the gist..

  13. Also one downside to this is that it filters all the wp_list_pages so on an site_map page you will see the page descriptions as well...

  14. You must be a logged-in exclusive member to view this reply.

  15. I meant to ask you about the styling of this menu...

    I know that this validates strict
    I currently have it as a <p class="page-text">page description</p>

    can you see any reason why it would be better to have

    <span>page description</span>

    no rush in answering this one just thinking aloud, or maybe those are other voices I am hearing in my head... or it could just be its so cold here atm

    Local weather temp

  16. You must be a logged-in exclusive member to view this reply.

  17. Ok thanks for the input,

    if you have the time and feel like being nosy.. some screencaps of what is going live shortly, still some css to tweak and other bits and bobs

    Front-page
    Services-page
    404-page

    Thanks

  18. You must be a logged-in exclusive member to view this reply.

  19. Yep, plenty of tidying up to to do, also have to add another (I know that your not a fan of) jQuery slider for the portfolio page which I am having fun coding atm it will continiously scroll showing 6 medium imgs and automatically pull thetaxs` out from the posts and be tab selectable without refreshing the page if you follow me (not to worry)

    all taxs    tax1   tax2  tax3  tax 4    etc
    
    <-  |-----  image-----image-----image----- | ->
    <-  |-----  image-----image-----image----- | ->

    sure that you will have me on here pulling my hair out again...

    thanks for the thumbs up,

    Do you think there would be much interest for this as a child theme, I have done my best to make sure that it isn't so specified to my needs, maybe as a Portfoilo child theme for Hybrid??

  20. Screen caps removed

  21. You must be a logged-in exclusive member to view this reply.

Reply

You must log in to post.

Limited Access

If you have an account, please take a moment to log in.

Non-exclusive members have limited access to the support forums.

To enjoy the full range of support, sign up for an exclusive membership in the theme club.

Support Forums

  • Bliss Theme (202 posts)
  • Hybrid Theme (17,110 posts)
  • Options Theme (10,322 posts)
  • Structure Theme (2,626 posts)
  • Visionary Theme (767 posts)
  • bbPress Themes (293 posts)
  • WordPress Plugins (1,619 posts)
  • General Discussion (4,010 posts)