Welcome, guest!

Feel free to read the blog, browse for themes, or join the club.

How to add page menu items to 'cat-nav' category menu in Hybrid News?

  1. Hi there. I am using the latest 'Hybrid News' child theme and have the dropdown menu that displays the post categories. I need to add some page menu items to it like 'Home' and 'About' to it.

    Is this possible and what file(s) and code would I change?

    Kind regards, Ian

  2. http://themehybrid.com/support/topic/easy-hybrid-theme-navigation-menu#post-19311

  3. Thanks for the fast response Thomas.
    I added that code to the functions.php file in 'Hybrid News' but it is not displaying the extra menu link.

    Is there a certain place I should have added it in? I just pasted it in right after another filter.

    This is my file code:

    <?php
    
    /**
    * This is your child theme's functions.php file.
    * You should make edits and add additional code above this point.
    * Only change the functions below if you know what you're doing.
    */
    
    /********************************************************/
    
    /* Constant paths. */
    	define( HYBRID_NEWS, get_stylesheet_directory() );
    	define( HYBRID_NEWS_URL, get_stylesheet_directory_uri() );
    
    /* For localization. */
    	load_theme_textdomain( 'news', HYBRID_NEWS );
    
    /* Hybrid News theme settings. */
    	$news_settings = get_option( 'hybrid_news_theme_settings' );
    
    /* Include admin files. */
    	if ( is_admin() )
    		require_once( HYBRID_NEWS . '/library/admin/theme-settings.php' );
    
    /* Actions. */
    	add_action( 'hybrid_head', 'news_front_page_template' );
    	add_action( 'wp_head', 'news_remove_actions' );
    	add_action( 'hybrid_before_header', 'hybrid_page_nav' );
    	add_action( 'hybrid_header', 'news_get_header_widget', 11 );
    	add_action( 'hybrid_after_header', 'news_cat_nav' );
    	add_action( 'hybrid_after_header', 'hybrid_breadcrumb' ); // new action added by Ian
    	add_action( 'hybrid_after_header', 'hybrid_search_form' ); // new action added by Ian
    	add_action( 'hybrid_after_container', 'news_widget_container', 11 );
    	add_action( 'hybrid_after_single','news_author_box' );
    	add_action( 'widgets_init', 'news_register_widget_areas' );
    
    /* Filters. */
    	add_filter( 'hybrid_post_meta_boxes', 'news_post_meta_boxes' );
    	add_filter( 'hybrid_category_menu', 'custom_cat_nav' ); // new filter added by Ian
    
    function custom_cat_nav( $menu ) {
    	$menu = false;
    	$menu = '<ul id="cat-nav" class="menu sf-menu">';
    	$menu .= '<li><a href="http://somelink.com">Some link</a></li>';
    	$menu .= wp_list_categories( array( 'depth' => 4, 'exclude' => '4,7',  'title_li' => false, 'echo' => 0 ) );
    	$menu .= '</ul>';
    	return $menu;
    }
    
    /**
     * Removes default Hybrid theme actions
     *
     * @since 0.1
     */
    function news_remove_actions() {
    	remove_action( 'hybrid_after_header', 'hybrid_page_nav' );
    	remove_action( 'hybrid_after_container', 'hybrid_get_primary' );
    	remove_action( 'hybrid_after_container', 'hybrid_get_secondary' );
    	remove_action( 'hybrid_before_content', 'hybrid_breadcrumb' ); // new action added by Ian
    }
    
    /**
     * Displays the category menu.
     *
     * @since 0.2
     */
    function news_cat_nav() {
    
    	$args = array(
    		'style' => 'list',
    		'hide_empty' => true,
    		'use_desc_for_title' => false,
    		'depth' => 4,
    		'hierarchical' => true,
    		'echo' => false,	// Leave as is.
    		'title_li' => false,	// Leave as is.
    	);
    
    	echo "\n\t<div id='cat-navigation'>\n\t\t";
    
    	echo '<div id="cat-nav" class="cat-nav"><ul class="menu sf-menu">' . str_replace( array( "\t", "\n", "\r" ), '', wp_list_categories( $args ) ) . '</ul></div>';
    
    	echo "\n\t</div>\n";
    }
    
    /**
     * Register additional widget areas
     *
     * @since 0.1.1
     */
    function news_register_widget_areas() {
    	register_sidebar( array( 'name' => __('Tertiary', 'news'), 'id' => 'tertiary', 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
    	register_sidebar( array( 'name' => __('Utility: Header', 'news'), 'id' => 'utilityheader', 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
    }
    
    /**
     * Adds JavaScript and CSS to Front Page page template.
     * Also removes the breadcrumb menu.
     *
     * @since 0.1
     */
    function news_front_page_template() {
    	if ( is_page_template( 'front-page.php' ) ) :
    		wp_enqueue_script( 'slider', HYBRID_NEWS_URL . '/library/js/jquery.cycle.js', array( 'jquery' ), 0.1 );
    		wp_enqueue_script( 'slider-functions', HYBRID_NEWS_URL . '/library/js/jquery.functions.js', array( 'jquery' ), 0.1 );
    		wp_enqueue_style( 'front-page', HYBRID_NEWS_URL . '/front-page.css', false, '0.1', 'screen' );
    		wp_enqueue_style( 'hybrid_before_container', 'hybrid_breadcrumb' );
    	endif;
    }
    
    /**
     * Displays the Utility: Header widget section
     *
     * @since 0.1
     */
    function news_get_header_widget() {
    	if ( is_active_sidebar( 'utilityheader' ) ) :
    		echo '<div id="utility-header" class="utility">';
    		dynamic_sidebar( 'utilityheader' );
    		echo '</div>';
    	endif;
    }
    
    /**
     * Wraps the Primary, Secondary, and Tertiary widget sections.
     *
     * @since 0.1
     */
    function news_widget_container() {
    	if ( is_active_sidebar( 'primary' ) || is_active_sidebar( 'secondary' ) || is_active_sidebar( 'tertiary' ) ) :
    		echo '<div id="widget-container">';
    			hybrid_get_primary();
    			hybrid_get_secondary();
    			news_get_tertiary();
    		echo '</div>';
    	endif;
    }
    
    /**
     * Displays the Tertiary widget section.
     *
     * @since 0.1
     */
    function news_get_tertiary() {
    	if ( is_active_sidebar( 'tertiary' ) ) :
    		echo '<div id="tertiary">';
    		dynamic_sidebar( 'tertiary' );
    		echo '</div>';
    	endif;
    }
    
    /**
     * Shows an author description after the post.
     * Only shows on single post.
     *
     * @since 0.1
     */
    function news_author_box() {
    	global $hybrid_settings;
    ?>
    	<div class="author-profile vcard">
    		<?php echo get_avatar( get_the_author_email(), '96', $hybrid_settings['default_avatar'] ); ?>
    		<h4 class="author-name fn n"><?php the_author_posts_link(); ?></h4>
    		<p class="author-description author-bio">
    			<?php the_author_description(); ?>
    		</p>
    	</div>
    <?php
    }
    
    /**
     * Add additional post meta boxes.
     * - Feature image input box.
     *
     * @since 0.1
     */
    function news_post_meta_boxes( $meta_boxes ) {
    	$meta_boxes['medium'] = array( 'name' => 'Medium', 'default' => '', 'title' => __('Medium/Feature:', 'news'), 'type' => 'text', 'show_description' => false, 'description' => false );
    	return $meta_boxes;
    }
    
    ?>
  4. You must be a logged-in exclusive member to view this reply.

  5. Hi there. I believe it didn't work because there was already a 'function news_cat_nav'

    I got it working by modifying that part instead to this:

    echo "\n\t<div id='cat-navigation'>\n\t\t";
    
    	echo '<div id="cat-nav" class="cat-nav"><ul class="menu sf-menu"><li><a href="http://www.example.org">Home</a></li><li><a href="http://www.example.org/about/">About</a></li>' . str_replace( array( "\t", "\n", "\r" ), '', wp_list_categories( $args ) ) . '</ul></div>';
    
    	echo "\n\t</div>\n";

    This is fine when just using urls, but in my case if the client changes the url of a page this hardcoded link will break. Also it only displays the top level page and not the sub-pages under it. I could hard code them too, but not ideal as if more pages are added, then they would also need to be added to 'functions.php'.

  6. Fixed by adding in page ID's, it is manual though but gives me control for which pages to display in the category menu.

    echo '<div id="cat-nav" class="cat-nav"><ul class="menu sf-menu">';
    	echo '<li><a href="http://www.example.com">Home</a></li>';
    
    	echo str_replace( array( "\t", "\n", "\r" ), '', wp_list_categories( $args ) );
    	wp_list_pages( array( 'include' => '2,23,60,25,58,81', 'title_li' => false ) ); // Displays About page and it's subpage IDs
    
    	echo '</ul></div></div>';

Reply

You must log in to post.

Limited Access

If you have an account, please take a moment to log in.

Non-exclusive members have limited access to the support forums.

To enjoy the full range of support, sign up for an exclusive membership in the theme club.

Support Forums

  • Bliss Theme (199 posts)
  • Hybrid Theme (17,011 posts)
  • Options Theme (10,322 posts)
  • Structure Theme (2,624 posts)
  • Visionary Theme (767 posts)
  • bbPress Themes (293 posts)
  • WordPress Plugins (1,617 posts)
  • General Discussion (3,976 posts)