Blog menu

Hi, how do I add a new navigation menu just for the blog page? I’d like to include new page items exclusively for the blog page.

@dstt0001

I would recommend you to look a plugin that allows you to use multiple menus. Since this theme uses regular WordPress menu structure it shouldn’t be a problem to implement if as long as there is a plugin for that.

If not you will have to register a new menu like this:

	register_nav_menus( array(
		'blogmenu' => __( 'Primary Menu', 'sparkling' ),
	) );
	if ( ! function_exists( 'sparkling_header_blogmenu' ) ) :
/**
 * Header menu for blog (should you choose to use one)
 */
function sparkling_header_blogmenu() {
  // display the WordPress Custom Menu if available
  wp_nav_menu(array(
    'menu'              => 'blogmenu',
    'theme_location'    => 'primary',
    'depth'             => 2,
    'container'         => 'div',
    'container_class'   => 'collapse navbar-collapse navbar-ex1-collapse',
    'menu_class'        => 'nav navbar-nav',
    'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
    'walker'            => new wp_bootstrap_navwalker()
  ));
} /* end header menu */
endif;

Then you can use conditional tags that are in WordPress to output menu when and where you need it.

basic idea for conditional tags would be like this:

<?php if is_front_page() : ?>
	<?php sparkling_header_blogmenu(); ?>
<?php else :?>
	<?php sparkling_header_menu(); ?> 

This is just an example and simple copy/paste won’t do a thing as it depends on what exactly you are trying to achieve. You are going to be better of using some plugin if there is any.

Thanks

Where exactly do I write this additional code? In the functions.php file of my Childtheme?
Here is how I have it now:

if ( ! function_exists( 'sparkling_featured_slider' ) ) :
/**
 * Featured image slider, displayed on front page for static page and blog
 */
function sparkling_featured_slider() {
  if ( is_front_page() && of_get_option( 'sparkling_slider_checkbox' ) == 1 ) {
    echo '<div class="flexslider">';
      echo '<ul class="slides">';
        $count = of_get_option( 'sparkling_slide_number' );
        $slidecat =of_get_option( 'sparkling_slide_categories' );
        $query = new WP_Query( array( 'cat' =>$slidecat,'posts_per_page' =>$count ) );
        if ($query->have_posts()) :
          while ($query->have_posts()) : $query->the_post();
          echo '<li>';
            if ( (function_exists( 'has_post_thumbnail' )) && ( has_post_thumbnail() ) ) :
              echo get_the_post_thumbnail();
            endif;
              echo '<div class="flex-caption">';
                  if ( get_the_title() != '' ) echo '<h2 class="entry-title">'. get_the_title().'</h2>';
                  if ( get_the_excerpt() != '' ) echo '<div class="excerpt">' . get_the_excerpt() .'</div>';
              echo '</div>';
              endwhile;
	        endif;

          echo '</li>';
      echo '</ul>';
    echo ' </div>';
  }
}
endif;

Please read this line again:

This is just an example and simple copy/paste won’t do a thing as it depends on what exactly you are trying to achieve. You are going to be better of using some plugin if there is any.

If you don’t know where to put this code then this solution is obviously not for you. Look for WordPress plugin on WordPress.org plugin repository instead. Otherwise you will break your website completely.