Hello and welcome to our first Tech Tip Tuesday, MIGHTYminnow’s very own tips & tricks series. Stay tuned for more…
WordPress’ native wp_list_pages() function is great for doing just what it sounds like – outputting a clean list of pages with one line of code – but sometimes we need to do more.
The following code goes in your theme’s functions.php file and can be used to output a list of pages, in which pages are included or excluded if their title contains a specified “test string.”
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 | <?php // Get an array of all pages $pages=get_pages(); // Get ID's of pages with "test string" in title foreach($pagesas$page){ if(stristr($page->post_title,'test string')){ $exclude_ids.=$page->ID.','; } } // Output pages, excluding the ones with "test string" in their title $args=array( 'exclude'=>$exclude_ids, 'title_li'=>'' ); wp_list_pages($args); ?> |