Theme twentyeleven Version 1.5
HELP PLEASE
I have received an answer from @Mayeenul Islam but this has not resolved my question, if I can't make the navigation show active that's not the end of the world but I would really like to resolve the title and name issue below using what I have coded.
I have tried my hardest to find the answer myself. PHP Novice ;o/
As I can't find a way to style the blogs main navigation to match clients main site I have removed this:
<nav id="access" role="navigation">
<h3 class="assistive-text"><?php _e( 'Main menu', 'twentyeleven' ); ?></h3>
<?php /* Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff. */ ?>
<div class="skip-link"><a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to primary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to primary content', 'twentyeleven' ); ?></a></div>
<div class="skip-link"><a class="assistive-text" href="#secondary" title="<?php esc_attr_e( 'Skip to secondary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to secondary content', 'twentyeleven' ); ?></a></div>
<?php /* Our navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assigned to the primary location is the one used. If one isn't assigned, the menu with the lowest ID is used. */ ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
</nav><!-- #access -->
and replaced with this:
<nav id="access" role="navigation">
<ul>
<li><a href="<?php echo esc_url( get_permalink( get_page_by_path( 'the-blx' ) ) ); ?>">Home</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo esc_url( get_permalink( get_page_by_path( 'what-the-blx-does' ) ) ); ?>">What The BLX Does</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'business-finance' ) ); ?>">Business Finance</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'business-general' ) ); ?>">Business General</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'blx-news' ) ); ?>">BLX News</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'book-of-blx' ) ); ?>">Book of BLX</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'johns-rant' ) ); ?>">John’s Rant</a></li>
</ul>
</nav><!-- #access -->
The BLX is set in the reading settings> A static page> Post page.
Now I have three issue:
STYLING
1) The #access ID in style.css was setting the font as bold when on that page but has stopped working.
#access .current-menu-item > a,
#access .current-menu-ancestor > a,
#access .current_page_item > a,
#access .current_page_ancestor > a {
font-weight: bold;
}
CODING
For Page and Category - instead of have What The BLX Does (page) or Business (category)
1) I would like to pass the page title
2) I would like to pass the a href title tag
So it would be something like this.
<li><a href="<?php echo esc_url( get_permalink( get_page_by_path( 'what-the-blx-does' ) ) ); ?>" title="<?php get_page_by_title( );?>"><?php get_page_by_title( );?></a></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'business-general' ) ); ?>" title="<?php get_category_by_title( );?>"><?php get_category_by_title( );?></a></li>
Any help would be greatly appreciated.
Thanks
Dave
Theme twentyeleven Version 1.5
HELP PLEASE
I have received an answer from @Mayeenul Islam but this has not resolved my question, if I can't make the navigation show active that's not the end of the world but I would really like to resolve the title and name issue below using what I have coded.
I have tried my hardest to find the answer myself. PHP Novice ;o/
As I can't find a way to style the blogs main navigation to match clients main site I have removed this:
<nav id="access" role="navigation">
<h3 class="assistive-text"><?php _e( 'Main menu', 'twentyeleven' ); ?></h3>
<?php /* Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff. */ ?>
<div class="skip-link"><a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to primary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to primary content', 'twentyeleven' ); ?></a></div>
<div class="skip-link"><a class="assistive-text" href="#secondary" title="<?php esc_attr_e( 'Skip to secondary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to secondary content', 'twentyeleven' ); ?></a></div>
<?php /* Our navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assigned to the primary location is the one used. If one isn't assigned, the menu with the lowest ID is used. */ ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
</nav><!-- #access -->
and replaced with this:
<nav id="access" role="navigation">
<ul>
<li><a href="<?php echo esc_url( get_permalink( get_page_by_path( 'the-blx' ) ) ); ?>">Home</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo esc_url( get_permalink( get_page_by_path( 'what-the-blx-does' ) ) ); ?>">What The BLX Does</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'business-finance' ) ); ?>">Business Finance</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'business-general' ) ); ?>">Business General</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'blx-news' ) ); ?>">BLX News</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'book-of-blx' ) ); ?>">Book of BLX</a></li>
<li><span class="pipe">|</span></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'johns-rant' ) ); ?>">John’s Rant</a></li>
</ul>
</nav><!-- #access -->
The BLX is set in the reading settings> A static page> Post page.
Now I have three issue:
STYLING
1) The #access ID in style.css was setting the font as bold when on that page but has stopped working.
#access .current-menu-item > a,
#access .current-menu-ancestor > a,
#access .current_page_item > a,
#access .current_page_ancestor > a {
font-weight: bold;
}
CODING
For Page and Category - instead of have What The BLX Does (page) or Business (category)
1) I would like to pass the page title
2) I would like to pass the a href title tag
So it would be something like this.
<li><a href="<?php echo esc_url( get_permalink( get_page_by_path( 'what-the-blx-does' ) ) ); ?>" title="<?php get_page_by_title( );?>"><?php get_page_by_title( );?></a></li>
<li><a href="<?php echo get_category_link( get_category_by_slug( 'business-general' ) ); ?>" title="<?php get_category_by_title( );?>"><?php get_category_by_title( );?></a></li>
Any help would be greatly appreciated.
Thanks
Dave
Share Improve this question edited Aug 8, 2013 at 15:35 Dave asked Aug 7, 2013 at 11:48 DaveDave 375 bronze badges1 Answer
Reset to default 1STYLING
With a static navigation, the CSS you mentioned, won't work. Use the simple HTML parameters:
#access a:link,
#access a:active,
#access a:visited{
font-weight: bold;
}
CODING
In my project, I used echo get_the_category_by_ID( 11 );
to echo the Category name of the cat_ID = 11. You can show the cat name by this. For page title you can use <?php echo get_page($id); ?>
. But get_page() is deprecated. So instead of these, I'd love to place a single query, and then would love to echo one by one from the array, using get_pages()
:
get_pages(): This function returns an array of pages that are in the blog, optionally constrained by parameters. This array is not tree-like (hierarchical).
<?php $args = array(
'sort_order' => 'ASC',
'sort_column' => 'post_title',
'hierarchical' => 1,
'exclude' => '', //if you want to exclude any specific page
'include' => '', //pass the IDs here
'parent' => -1,
'number' => '',
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish'
);
$get_all_my_pages = get_pages( $args );
?>
To use the output, var_dump the variable (<?php var_dump( $get_all_my_pages ); ?>
) and work with it. So the <li>
for page would be:
<ul>
<li><a href="<?php echo $get_all_my_pages[0]['guid']; ?>" title="<?php echo $get_all_my_pages[0]['post_title']; ?>"><?php echo $get_all_my_pages[0]['post_title']; ?></a></li> <!-- for the first page of the output array -->
<li><a href="<?php echo $get_all_my_pages[4]['guid']; ?>" title="<?php echo $get_all_my_pages[4]['post_title']; ?>"><?php echo $get_all_my_pages[4]['post_title']; ?></a></li> <!-- for the fourth page of the output array -->
</ul>
I din't try the code, but things can be similar like this. And a similar thing can be done for categories too, with get_categories()
.
get_categories(): Returns an array of category objects matching the query parameters.
Please let me know whether it works...
Using only two queries your page will load faster. :)