WordPress.org

Ready to get started?Download WordPress

Forums

Showing children list and category posts on certain parent and child pages (3 posts)

  1. micasuh
    Member
    Posted 4 years ago #

    On my site, I'm trying to customize the sidebar to be specific to a parent and its children by listing related parent/children pages as well as listing relevant category posts.

    So, within a new UL, I have the following code:

    <ul class="events">
    				<?php if (is_page()) {
    						//we're looking at a static page again. Which pages?
    						if (is_page(array(5, 1752, 1768, 1749, 1764, 1775, 1754, 89, 1758)) && $post->post_parent)
    						// Children's pages and subpages
    						query_posts('cat=20&posts_per_page=10');
    						elseif (is_page(array(6, 630, 1878, 1882, 779, 1880, 1884)) && $post->post_parent)
    						// Adult pages and subpages
    						query_posts('cat=62&posts_per_page=10');
    						else query_posts('cat=12&posts_per_page=10');
    						}
    						while(have_posts()) : the_post(); ?>
    				<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    				<?php endwhile; ?>
    			</ul>

    If I am on page id=5 and any of its children, and likewise id=6 or any of its children, I want a list of only category 20 or 62 title links respectfully to appear on each page.

    The end resulting lists would be different from 5 to 6 and then default list on the rest of the WP pages.

  2. micasuh
    Member
    Posted 4 years ago #

    I'm confused why this worked but when I added the parent page as a child to another page, everything kicked in correctly. I'm confused why it wouldn't show these elements when this page is a top level parent page. That's ultimately what I need to happen here.

  3. micasuh
    Member
    Posted 4 years ago #

    Here's the whole page worth of code. I really hope someone can educate me!

    <?php
    if($post->post_parent) {
    	$parent = get_post($post->post_parent);
    	if ($parent->post_parent) {
    		$children = wp_list_pages("depth=1&sort_column=menu_order&title_li=&child_of=".$parent->ID."&echo=0");
    	} else {
    		$children = wp_list_pages("depth=1&sort_column=menu_order&title_li=&child_of=".$post->ID."&echo=0");
    	}
    }
    if ($children) { ?>
      <h3>Related Programs</h3>
      <ul class="moreInfo">
      <?php echo $children; ?>
      <?php if (is_page()) {
    			//we're looking at a static page. Which one?
    			if (is_page(5) && $post->post_parent) {
    				// Children's page and subpages
    				?><li class="page_item"><a href="http://www.terraceumc.org/category/children">Children's Upcoming Events</a></li><?php
    			} elseif (is_page(6) && $post->post_parent) {
    				// Adult page and subpages
    				?><li class="page_item"><a href="http://www.terraceumc.org/category/adults">Adult Ministries Upcoming Events</a></li><?php
    			}
    		} ?>
      </ul>
    <?php } ?>
    <!-- End Related Pages -->	
    
    <h3>What's News&mdash;</h3>
    <ul class="events">
    	<?php if (is_page()) {
    			//we're looking at a static page again. Which pages?
    			if (is_page(array(5, 1752, 1768, 1749, 1764, 1775, 1754, 89, 1758)) && $post->post_parent)
    			// Children's page and subpages
    			query_posts('cat=20&posts_per_page=10');
    			elseif (is_page(array(6, 630, 1878, 1882, 779, 1880, 1884)) || $post->post_parent)
    			// Adult page and subpages
    			query_posts('cat=62&posts_per_page=10');
    			else query_posts('cat=12&posts_per_page=10');
    			}
    			while(have_posts()) : the_post(); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<?php endwhile; ?>
    	<li class="all"><a href="<?php bloginfo('url'); ?>/category/events/">View All Upcoming Events</a></li>
    </ul>

Topic Closed

This topic has been closed to new replies.

About this Topic