• Resolved mattd79

    (@mattd79)


    Hi guys,

    Loving the Hueman theme but I have one problem regarding the displaying of the Child Menu. I understand how to show this on Pages and it works very well, but can anyone point me in the right direction for including the Child Menu in a Sidebar so that it is also shown for Posts as well?

    (As has been mentioned here before, simply adding the Show Pages widget to the sidebar doesn’t look as pretty, so want to show the Child Menu.)

    Any help would be kindly appreciated.

    Cheers,

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi mattd79. I haven’t tested this but you might give it a try:

    1. Copy sidebar.php to a child theme.

    2. Change this line:

    <?php if( is_page_template('page-templates/child-menu.php') ): ?>

    to include the single post template:

    <?php if( is_page_template('page-templates/child-menu.php') || is_page_template('single.php') ): ?>
    Thread Starter mattd79

    (@mattd79)

    Hi bdbrown, thanks for that but still didn’t work I’m afraid.
    I copied in the line as you suggested into the sidebar.php to reference single.php but no change.

    Any more suggestions guys?

    OK. More research seems to indicate that single.php isn’t a page template in the sense of the is_page_template() function. Maybe try just is_single():

    <?php if( is_page_template('page-templates/child-menu.php') || is_single() ): ?>

    If that doesn’t work you might try modifying the code block to include a separate section for posts. Since single.php isn’t a “page” directly related to the menu pages, we can try building the menu manually. The following change should build the child menu based on the designated parent page ID, so you’d need to change $parent = 99 to the page ID for your menu parent page. Again, I haven’t tested this; it’s just an idea I’m tossing out there.

    <?php if( is_page_template('page-templates/child-menu.php') ): ?>
    	<ul class="child-menu group">
    		<?php wp_list_pages('title_li=&sort_column=menu_order&depth=3'); ?>
    	</ul>
    <!-- adding new section to build child menu for post page -->
    <?php elseif( is_single() ): ?>
    	<?php
    	// use wp_list_pages to display parent and all child pages all generations (a tree with parent)
    	$parent = 99;
    	$args=array(
    		'child_of' => $parent
    	);
    	$pages = get_pages($args);
    	if ($pages) {
    		$pageids = array();
    		foreach ($pages as $page) {
    			$pageids[]= $page->ID;
    		}
    		$args=array(
    			'title_li' => '',
    			'sort_column' => 'menu_order',
    			'depth' => 3,
    			'include' =>  $parent . ',' . implode(",", $pageids)
    		);
    		wp_list_pages($args);
    	}
    	?>
    <?php endif; ?>

    Here is the Codex reference for the above code.

    Thread Starter mattd79

    (@mattd79)

    Hi bdbrown, thanks again for your help. Progress using your latter suggestion smiley face. I set the ‘depth’ => 2, and the menu is displaying the correct list now so that is brilliant thank you for that.
    Using wp_list_pages I now have the right list of menu items, but any suggestions on how I could set the formatting so that it is the same as the Child Menu? i.e., it is currently displayed as a list of links rather than ‘menu blocks’ if that makes sense?

    Cheers,
    Matt

    Can you post a link to your site so we can see what you’re describing? thanks.

    Thread Starter mattd79

    (@mattd79)

    Hi, sure, it’s: https://www.runningfastr.com – You’ll see the homepage is showing the Child Menu but then if you click on any of the Posts such as Training Workouts it has the unformatted wp_pages_list as you prescribed.

    Cheers,
    Matt

    Give this a try. Change the end of the code block to this:

    );
    	echo '<ul class="child-menu group">';
    	wp_list_pages($args);
    	echo '</ul>';
    }

    Then add this css:

    .single .sidebar .child-menu li {
      display: block;
    }
    Thread Starter mattd79

    (@mattd79)

    Thank you bdbrown, that worked a treat. Child Menu’s are now showing on the Post pages as well, thanks again.

    Cheers,
    Matt

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Hueman-can you show Child Menu for Posts’ is closed to new replies.