How to add a slug to nav and link to a WPMU page
-
Hi all!
I’m feeling quite proud of myself this evening and just had to share this.
Thanks to the great folks in these here forums, I (a true-blue php-dummy) figured out how to add a new slug to the main navbar, link it to a WPMU page and highlight the slug when on the page. Hooray!
1 – Define the slug in wp-config.php, just before the line where it says “Stop Editing!” like so:
define ( “BP_PAGE_SLUG”, ‘wpmu-page-name‘ );
2 – Add the slug into header.php (somewhere around line 87) like so:
<li<?php if ( is_page( BP_PAGE_SLUG ) ) : ?> class=”selected”<?php endif; ?>>/<?php echo BP_PAGE_SLUG ?>” title=”<?php _e( ‘Slug Label‘, ‘buddypress’ ) ?>”><?php _e( ‘Slug Label‘, ‘buddypress’ ) ?>
3 – Make sure that ?php if ( bp-is_page is truncated to ?php if ( is_page
Removing the “bp-” ensures that, when linking to a WPMU created page, the slug is properly highlighted when on that page.
It works. Thanks to all who contribute here. Now I can go to bed a little more knowledgeable.
-
Just got a message from jeffreeeeey saying the code isn’t displaying properly. Oops, forgot to enclose it in tags. Here it is (hopefully..):
<li<?php if ( is_page( BP_PAGE_SLUG ) ) : ?> class="selected"<?php endif; ?>>/<?php echo BP_PAGE_SLUG ?>" title="<?php _e( 'Slug Label', 'buddypress' ) ?>"><?php _e( 'Slug Label', 'buddypress' )</li>
Correct code:
<li<?php if ( is_page( BP_PAGE_SLUG ) ) : ?> class="selected"<?php endif; ?>>/<?php echo BP_PAGE_SLUG ?>" title="<?php _e( 'Slug Label', 'buddypress' ) ?>"><?php _e( 'Slug Label', 'buddypress' )</li>
I haven’t tried it yet. But what do I do, if I have more than one static wpmu page?
Do I just name it BP_PAGE2_SLUG?
Please explain some more…
Greetings
Neobond
Use wp_list_pages in bp_nav_items action to display all pages in tab menu.
define( 'BP_CUSTOM_PAGE_SLUG', 'overview' );
add_action( 'bp_nav_items', my_bp_nav_items);function my_bp_nav_items () {
// wp_list_pages('title_li=');
$class = is_page( BP_CUSTOM_PAGE_SLUG )? 'class="selected"' : '';
$url = get_bloginfo('url').'/blog/'.BP_CUSTOM_PAGE_SLUG;
?>
<li<?php echo $class; ?><a href="<?php echo $url; ?>"
title="<?php _e( 'Overview ', 'oc' ); ?>">
<?php _e( 'Overview', 'oc' ); ?>
</a></li>
<?php }hi epsi,
thanks, but I couldn’t get it to work with more than one static wpmu page. How should the code look like, if you have like “page1”, “page2” and “page3”?
And how do I order them in the nav bar? Right now the page in your example gets just added after the last of the build-in nav items…just place the function-code in between the other items in header.php?
So far I only tried to add the piece of code into wp-config.php or into bp-custom.php.
More help would be very appreciated.
Cheers Neo
- The topic ‘How to add a slug to nav and link to a WPMU page’ is closed to new replies.