Forums

[resolved] [Theme: modmat] want to exclude some pages from navigation (21 posts)

  1. Steve Rodgers
    Member
    Posted 3 years ago #

    Hi I am using the modmat theme.

    Instead of putting wp_list_pages() in the header, the designer just linked navigation to the sandbox_globalnav within the theme's functions.

    While it looks great and works great, I want to be able to exclude some pages from the header navigation depending on which page you are on.

    Anyone have any clues how I can alter the functions to make this possible?

    Thanks in advance,
    -Steve

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    This will give you the Page ID being queried

    <?php
    $pageid = get_query_var('page_id');
     echo 'page query var' . $pageid;
    
    ?>
  3. Steve Rodgers
    Member
    Posted 3 years ago #

    thanks for that, but I'm still not sure how it applies in this case.

    I mean, should this go in the header or in the sandbox functions?

    I do apologize for ignorance, I'm not good with php code, but I sure am a hammerhead when it comes to getting stuff like this straightened out ;)

  4. MichaelH
    Volunteer
    Posted 3 years ago #

    You will need to make this clearer:

    I want to be able to exclude some pages from the header navigation depending on which page you are on.

  5. Steve Rodgers
    Member
    Posted 3 years ago #

    for instance, If I have pages "Home | About | Hot Rods | Street Bikes"

    I would like to exclude "Hot Rods" from the header navigation when the visitor is on the page and child pages about 'street bikes'. I would only want to show Home | About| and Street Bike and Street Bike child pages. Vice Versa as well.

    I found a way to do this in the codex, but not when the navigation is sandox_globalnav in the theme's functions.

    I'll list the code for you:

    <?php
    // Produces a list of pages in the header without whitespace -- er, I mean negative space.
    function sandbox_globalnav() {
    	echo '<div id="menu"><ul>';
    	echo '<li';
    	if ( is_home() ) {
    		echo ' class="current_page_item"';
    	}
    	echo '><a href="' . get_settings('siteurl') . '">Home</a></li>';
    	$menu = wp_list_pages('title_li=&sort_column=menu_order&depth=1&echo=0'); // Params for the page list in header.php
    	echo str_replace(array("\r", "\n", "\t"), '', $menu);
    	echo "</ul></div>\n";
    }

    The code in header.php:

    <div id="access">
    		<?php sandbox_globalnav() ?>
    	</div><!-- #access -->

    I'm not sure how to alter wp_list_pages in this case.

    Hope that's clearer,
    -Steve

  6. MichaelH
    Volunteer
    Posted 3 years ago #

    Well the child page thing is troublesome and makes this ugly but in sandbox.php replace:

    $menu = wp_list_pages('title_li=&sort_column=menu_order&depth=1&echo=0'); // Params for the page list in header.php

    with something like this:

    //assuming page 42 is Hot Rods
    if ( is_page('42') || $post_parent='42' ) {
    $menu = wp_list_pages('exclude=59,60,61,62&title_li=&sort_column=menu_order&depth=1&echo=0');
    }
    if ( is_page('59') || $post_parent='59' ) {
    $menu = wp_list_pages('exclude=42,43,44,45&title_li=&sort_column=menu_order&depth=1&echo=0');
    }

    Related:
    Page related Conditional Tags
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  7. Steve Rodgers
    Member
    Posted 3 years ago #

    do you think it would be a good idea for me to create a new function with the code you've just provided? For instance I'll keep the current sandbox_globalnav for the main header.

    But I can made page-specific headers that link to different function that I create from the code above.

    In other words I'll leave globalnav alone. I'll create a new function called function sandbox_hotrodnav() and put the code:

    <div id="access">
    		<?php sandbox_globalnav() ?>
    	</div><!-- #access -->
    in my custom header files.

    That way my main blog home stays unaltered and I will customize page templates to reflect what you've provided above.

    Am I on the right track here?

    -Steve

  8. MichaelH
    Volunteer
    Posted 3 years ago #

    Or just backup sandbox.php for now, and make the changes.

    But wouldn't it be --

    <div id="access">
    		<?php sandbox_hotrodnav() ?>
    	</div><!-- #access -->
  9. Steve Rodgers
    Member
    Posted 3 years ago #

    Yes. Typo, realized after I posted it.

    No luck, Michael.

    I replaced what you've suggested and wordpress is giving me a syntax error:

    unexpected $end on line 361

    That is the last line of sandbox where the php tag is closed.

    I was very careful to follow your instructions and checked it a few times, but I'm getting the same syntax error.

    Is there any more info I can provide for you to help remedy this?

  10. MichaelH
    Volunteer
    Posted 3 years ago #

    Please post your sandbox.php contents here.

  11. Steve Rodgers
    Member
    Posted 3 years ago #

    function sandbox_globalnav() {
    
    	echo '<div id="menu"><ul>';
    	echo '<li';
    	if ( is_home() ) {
    
    		echo ' class="current_page_item"';
    	}
    	echo '><a href="' . get_settings('siteurl') . '">Home</a></li>';
    	$menu = wp_list_pages('title_li=&sort_column=menu_order&depth=1&echo=0'); // Params for the page list in header.php
    	echo str_replace(array("\r", "\n", "\t"), '', $menu);
    	echo "</ul></div>\n";
    }
  12. MichaelH
    Volunteer
    Posted 3 years ago #

    I don't see where you made the changes.

  13. Steve Rodgers
    Member
    Posted 3 years ago #

    I put the original here. That's what I thought you were asking for.

    The changes you suggested gave me a syntax error message. The only part I changed was to the function sandbox_globalnav below.

    function sandbox_globalnav() {
    
    	echo '<div id="menu"><ul>';
    	echo '<li';
    	if ( is_home() ) {
    
    		echo ' class="current_page_item"';
    	}
    	echo '><a href="' . get_settings('siteurl') . '">Home</a></li>';
    	if ( is_page('107') || $post_parent='107' ) {
    $menu = wp_list_pages('exclude=112&title_li=&sort_column=menu_order&depth=1&echo=0');
    }
    if ( is_page('112') || $post_parent='112' ) {
    $menu = wp_list_pages('exclude=107&title_li=&sort_column=menu_order&depth=1&echo=0'); // Params for the page list in header.php
    	echo str_replace(array("\r", "\n", "\t"), '', $menu);
    	echo "</ul></div>\n";
    }

    Everything else was left unchanged. I'm backed up so I don't have any problems there.

    I was thinking I could just add if statements to sand_globalnav like you suggested, but unfortunately it didn't work out for me.

  14. MichaelH
    Volunteer
    Posted 3 years ago #

    Try:

    function sandbox_globalnav() {
    
    	echo '<div id="menu"><ul>';
    	echo '<li';
    	if ( is_home() ) {
    
    		echo ' class="current_page_item"';
    	}
    	echo '><a href="' . get_settings('siteurl') . '">Home</a></li>';
    	if ( is_page('107') || $post_parent='107' ) {
      $menu = wp_list_pages('exclude=112&title_li=&sort_column=menu_order&depth=1&echo=0');
      }
      if ( is_page('112') || $post_parent='112' ) {
      $menu = wp_list_pages('exclude=107&title_li=&sort_column=menu_order&depth=1&echo=0');
      }
    	echo str_replace(array("\r", "\n", "\t"), '', $menu);
    	echo "</ul></div>\n";
    }
  15. Steve Rodgers
    Member
    Posted 3 years ago #

    Thant definitely fixed the syntax. however I'm still running into an issue.

    Following our example-- Hodrods would be page 107 (a parent page)
    Streetbikes is page 112 (also a parent page)

    for some reason, using the code you've provided, the main navigation seems to get rid of Hotrods 107 altogether, but shows Streetbikes 112 regardless of which page you are on.

    If I reverse the two pieces of code the opposite shows is true (hodrods show, but streetbike is gone)

    Should I be using an else or elseif statement instead?

  16. MichaelH
    Volunteer
    Posted 3 years ago #

    An, menu would never get set, how about:

    $menu = wp_list_pages('title_li=&sort_column=menu_order&depth=1&echo=0'); // Params for the page list in header.php
    if ( is_page('107') || $post_parent='107' ) {
      $menu = wp_list_pages('exclude=112&title_li=&sort_column=menu_order&depth=1&echo=0');
      }
    if ( is_page('112') || $post_parent='112' ) {
      $menu = wp_list_pages('exclude=107&title_li=&sort_column=menu_order&depth=1&echo=0');
      }

    Just adding the one line before the if (is_page('107')..

  17. Steve Rodgers
    Member
    Posted 3 years ago #

    Thanks, Michael

    However I'm still getting the same effect though. It only seems to want to show the page designated in the second 'if' statement (page 112).

    Page 107 is still not listing itself where we're at right now.

    What a pain huh? :) I really appreciate you taking the time on this one.

  18. MichaelH
    Volunteer
    Posted 3 years ago #

    A bit more complicated than originally planned ;):

    $menu = wp_list_pages('title_li=&sort_column=menu_order&depth=1&echo=0'); // Params for the page list in header.php
      if ( is_page('') ); {
        global $wp_query;
        $page = $wp_query->post->ID;
        $parent = $wp_query->post->post_parent;
        if ( $page == '64' || $parent == '64' ) {
          $menu = wp_list_pages('exclude=93&title_li=&sort_column=menu_order&depth=1&echo=0');
        }
        if ( $page == '93' || $parent == '93' ) {
          $menu = wp_list_pages('exclude=64&title_li=&sort_column=menu_order&depth=1&echo=0');
        }
      }

    Of course, you know you are replacing the original
    $menu = wp_list_pages('title_li=&sort_column=menu_order&depth=1&echo=0'); // Params for the page list in header.php
    with the above

  19. Steve Rodgers
    Member
    Posted 3 years ago #

    Hi fives, Michael! That seemed to do the trick.

    However I'm running into another issue, but I'm not certain that it's related to this, but it might be.

    I checked your code against two different page parents (the ones I listed in the if/ exclude statement) and it works just fine.

    However when I publish a new parent page, it shows in navigation, which is great, but when you click the page, I'm getting an "Index of 'Pagetitle' page. Please note that the page looks fine in preview before publishing. It only does this when published.

    Could this be because I haven't indicated the page in our new globalnav code as a parent page?

    Would you prefer I opened a new ticket?

    Thank you for the awesome job you've done so far with the navbar :)

    -Steve

  20. Steve Rodgers
    Member
    Posted 3 years ago #

    Nevermind Michael,

    For some reason wordpress just didn't like that particular page id. I just erased and recopied into a new page.

    Thanks you very much! Job well done and much appreciated.

    -Steve

  21. cblcruz
    Member
    Posted 2 years ago #

    Hi Guys,
    I simply want to exclude on page from the entire site

    exclude=130

    where do I put that effectively?

    thanks for any help

Topic Closed

This topic has been closed to new replies.

About this Topic