More elegant nav solution? (1 post)

  1. patternicity
    Posted 2 years ago #

    Second post in the WP community, hooray!

    Anyways, I have some pages that are structured like this:

    First Level: Guides
    Second Level: Game 1, Game 2, Game 3, Game 4
    Third Level: Multiple guides for each game

    I have a sidebar to the side for navigating between the guides. It ONLY lists third-level pages for the second-level page you're on. (For example, if you're on the Game 1 page, it displays all Game 1's guides.)

    What I have right now is working as intended, but it requires two if statements. I'm wondering if there is a more elegant way to pull this off that only requires one statement. I'm fairly new to the WordPress world and my PHP knowledge isn't the greatest (though I'm fluent in HTML and CSS). Any help is appreciated.

    Here's the code:

    <!-- Check if parent page is 'Guides' and if so, display child pages (for second-level pages) -->
    	if(32 == $post->post_parent)
    		$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    		if ($children) { ?>
    			<ul class="nav nav-tabs nav-stacked">
    				<?php echo $children; ?>
    		<?php }
    <!-- Check if third-level page and if so, display same content as above -->
    			$parent_title = get_the_title($post->post_parent);?>
    		<?php echo $children;?>
    		<ul class="nav nav-tabs nav-stacked">
    			<?php wp_list_pages("title_li=&child_of=".$post->post_parent."&depth=1" );?>
    	<?php }?>

    Site is currently in private beta, so no link, sorry.


Topic Closed

This topic has been closed to new replies.

About this Topic