wp_list_pages issue/bug?
wp_list_pages issue/bug?
wp_list_pages issue/bug?
Working solution: /* Call using: [top_main_menu] */ add_shortcode( ‘top_main_menu’, ‘echo_top_main_menu’ ); function echo_top_main_menu() { $lookfor = array(‘page_item’); $replacewith = array(‘uk-hidden-small’); $args = array( ‘exclude’ => ‘134,115,104’, ‘echo’ => 0, ‘sort_column’ => ‘menu_order’, ‘title_li’ => __(”) ); $output = wp_list_pages( $args ); echo str_replace($lookfor,$replacewith,$output); }
Simply add the filter before the call and remove it afterward something like this <ul id=”headerlinks”> <?php add_filter(‘wp_list_pages’, ‘add_markup_pages’); wp_list_pages(‘title_li=&include=24,26,28,30’); remove_filter(‘wp_list_pages’, ‘add_markup_pages’); ?> </ul>
You can hook into the edit_posts_per_page filter that fires in WP_List_pages right before the pagination is determined. add_action( ‘edit_posts_per_page, ‘limit_list_pages’ ); function limit_list_pages() { $post_type=”post”; $edit_per_page=”edit_” . $post_type . ‘_per_page’; $per_page=(int)get_user_option( $edit_per_page ); if ( empty( $per_page ) || $per_page < 1 ) $per_page=10; //<— Change this to your new per page number return $per_page; … Read more
Got it working. This is the final code (pulled from http://cssglobe.com/post/5812/wordpress-find-pages-top-level-parent-id with little modification) <?php if ($post->post_parent) { $ancestors=get_post_ancestors($post->ID); $root=count($ancestors)-1; $parent = $ancestors[$root]; } else { $parent = $post->ID; } $children = wp_list_pages(“title_li=&child_of=”. $parent .”&echo=0&depth=1″); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?>
Your code won’t work if you have more than one parent page or multiple levels of child pages. Use get_ancestors to get the top parent page, and use the child_of argument of wp_list_pages rather than exclude to only output pages from that branch.
You may find this article I wrote over at WPtuts helpful. The following example I’ve adapted from that article. It lists all the top leve links, but only explores ancestors of the ‘current’ menu item. Hopefully the logic is clear with the comments: class WPSE73358_Ancestors_Only_Walker extends Walker_Nav_Menu { // Only follow down one branch function … Read more
You can use get_pages to do that: <?php $pages = get_pages(array(“child_of’ => get_the_ID())); ?> <ul class=”treatments-list h3″> <?php foreach ($pages as $page): ?> <li> <?php echo get_the_post_thumbnail($page->ID, ‘thumbnail’); ?> <h2> <a href=”https://wordpress.stackexchange.com/questions/77151/<?php echo get_permalink($page->ID); ?>” title=”<?php echo esc_attr($page->post_title);?>”> <?php echo $page->post_title; ?> </a> </h2> </li> <?php endforeach; ?> </ul>
If you don’t want them to ever be listed (using wp_list_pages at least) then you could hide them using a filter add_filter(‘wp_list_pages_excludes’, ‘my_page_excludes’); function my_page_excludes() { // the array should contain the page ids you want to exclude return array(1,6,7,12); } This will stop them from displaying in anything that lists pages using WordPress template … Read more
Consider this a complement to toscho’s solution. I believe that … $this->alternate = ($this->alternate != ‘background_1’) ? ‘background_1’ : ‘background_2′; $css_class[] = $this->alternate; … will do what you want. The difference is that toscho’s solution, using the static keyword, will make that variable static for any instantiation of this walker– that is, all instances will … Read more