[Theme: modmat] want to exclude some pages from navigation
-
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
-
This will give you the Page ID being queried
<?php $pageid = get_query_var('page_id'); echo 'page query var' . $pageid; ?>
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 ??
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.
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,
-SteveWell 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 Hierarchydo 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
Or just backup sandbox.php for now, and make the changes.
But wouldn’t it be —
<div id="access"> <?php sandbox_hotrodnav() ?> </div><!-- #access -->
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?
Please post your sandbox.php contents here.
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"; }
I don’t see where you made the changes.
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.
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"; }
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?
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’)..
- The topic ‘[Theme: modmat] want to exclude some pages from navigation’ is closed to new replies.