ThemeShaper Forums » Thematic

[closed]

menu with subtitles (how to restrict to certain pages)

(4 posts)
  • Started 13 years ago by anahya
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. Hello..

    Apolgy for any n00bness here, but I am in somewhat dire need of help. I used the menu trick with the subtitles from http://themeshaper.com/wordpress-menu-tricks/ and have yet to figure out how to make sure it only displays 3 specific pages. I know the include parameter, but I can't for the life of me figure out where to put the parameter there..

    My code is pretty much the same as the one in the tuturial. I'm using a childtheme.

    // First we need to remove the action creating the menu
    function remove_access($content) {
    	remove_action('thematic_header','thematic_access',9);
    }
    add_action('init', 'remove_access');
    
    // Now we need to rebuild it
    function childtheme_access() { ?>
    		<div id="access">
    
              <?php wp_page_menu(); ?>
    
        </div><!– #access –>
    		<?php }
    add_action('thematic_header','childtheme_access',9);
    
    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>$row->post_title</a>";
       echo "<span class=\"sub\">$row->meta_value</span>";
       echo "</li>
    ";
      }
     }
    }
    
    // Filter the menu to add the list
    function childtheme_page_menu() { ?>
        <div class="menu">
            <ul class="sf-menu">
    
                <?php sub_page_list(); ?>
    
        </div>
    <?php }
    add_filter('wp_page_menu','childtheme_page_menu');
    Posted 13 years ago #
  2. you only want that custom access div to display on 3 pages? Do you want anything at all on the other pages?

    http://codex.wordpress.org/Conditional_Tags

    I'd wrap your whole code up in some conditional statements. i haven't tested it, but it seems like it ought to work.

    if (is_page('pageslug1') OR (is_page('pageslug2') OR (is_page('pageslug3')){
    
    // First we need to remove the action creating the menu
    function remove_access($content) {
    	remove_action('thematic_header','thematic_access',9);
    }
    add_action('init', 'remove_access');
    
    // Now we need to rebuild it
    function childtheme_access() { ?>
    		<div id="access">
    
              <?php wp_page_menu(); ?>
    
        </div><!– #access –>
    		<?php }
    add_action('thematic_header','childtheme_access',9);
    
    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>$row->post_title</a>";
       echo "<span class=\"sub\">$row->meta_value</span>";
       echo "</li>
    ";
      }
     }
    }
    
    // Filter the menu to add the list
    function childtheme_page_menu() { ?>
        <div class="menu">
            <ul class="sf-menu">
    
                <?php sub_page_list(); ?>
    
        </div>
    <?php }
    add_filter('wp_page_menu','childtheme_page_menu');
    
    }
    
    else {
    // whatever you want to happen on the other pages.
    }
    Posted 13 years ago #
  3. I evidently explained this wrong.

    I am using a menu that "lists" 3 pages. About | Contact | Showreel
    When I add another page in WP it adds that as well, but I do not want this. I know the conditional tags necessary for wp_page_menu, but in the code snipped I showed it doesnt catch. It still adds the other page links to the menu, even when I restricted it to 3 specific IDs.

    Posted 13 years ago #
  4. this is the line from your above code that appears to be selecting which pages will show up in your menu.

    $sql .= "WHERE p.post_type = 'page' AND p.post_parent = 0 AND p.post_status = 'publish' ";

    it says you want to pull all top-level, published pages. so my guess (and my sql is even shakier than my php) would be to limit the query based on ID numbers:

    $sql .= "WHERE p.ID = 1 AND p.ID = 2 AND p.ID = 3 ";

    where the 1,2 and 3 are the IDs of the 3 pages you want to keep. again, my sql is just about non-existant. you might need '' around the numbers, i have no idea. And it may not work at all. Hopefully someone w/ a better understanding of sql can help you out.

    what about just hard coding your own menu? The code is available on the site you linked to and might be the easiest way.

    Posted 13 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.