Timing problem with code imported from Shortcode-exec-PHP
-
I have been using the following code in Shortcode Exec PHP to generate a context-sensitive menu which displays the ancestry of the current page, plus with its immediate siblings and children. Having imported this, the code looks identical: but the menu now displays every single page in the family tree, making it impracticably long! So I’ve had to revert to Shortcode Exec PHP for now.
I’m guessing this may be something to do with precisely when the code is being executed: but I can’t see any options for controlling this. Is there a simple fix?
//CONTEXT MENU code - defined as 'context_menu' in Shortcode Exec PHP //Invoked as [context_menu] in Sidebar Right text widget //if the post has no parent - it's a top-level page if(!$post->post_parent){ $relations = array(); // no ancestors //Search the database for any child and other top-level pages global $wpdb; $result = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_parent = $post->ID OR post_parent = 0)" ); }else{ //Tricky - First, request array of ancestor pages $relations = get_post_ancestors($post->ID); //Now search the database for any child and sibling pages global $wpdb; $result = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_parent = $post->ID OR post_parent = $post->post_parent)" ); } if ($result){ //Add any finds to the array foreach($result as $pageID){ array_push($relations, $pageID->ID); } } //Reduce array to a comma delimited list $relations_string = implode(",",$relations); //Now request a list of the collected pages, wrapped in <li> tags $sidelinks = wp_list_pages("title_li=&echo=0&include=".$relations_string); if ($sidelinks) { ?> <ul id="ContextMenu"> <? //Not an empty list, so wrap it in <ul> tags echo $sidelinks; ?> </ul> <? }
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Timing problem with code imported from Shortcode-exec-PHP’ is closed to new replies.