WordPress.org

Ready to get started?Download WordPress

Forums

if has child pages display them, if not do something else (2 posts)

  1. educationthemes
    Member
    Posted 6 years ago #

    In order to reduce the number of template in my theme I am using some conditional statements to change things on my pages. I am currently using this in my sidebar:

    <?php
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>
    <h2><?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?> Pages</h2>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } else
    wp_get_archives();
    ?>

    Basically this checks to see if the page has child pages, and if so it lists the child page links. If it doesn't have a child page then it list the archives.

    My problem is, is that I want it to list the posts titles from a certain category in an unordered list (wrapped in <ul> tags so that it displays correctly) if the page doesn't have child pages.

    Can anyone help me out on how to do this. The codex is full of example of conditional uses but none quite seem to match what I am looking for.

    Thanks in advance.

  2. angeljusto
    Member
    Posted 6 years ago #

    what about a simple loop:

    <?php
    query_posts("cat=xx");
    if( have_posts() ):
    ?>
    <ul>
    <?php
    while( $i=1; while (have_posts()) : the_post();
    ?>
    <li>
    <a href="<?=the_permalink()?>" title="<?=the_title()?>">
    <?= the_title(); ?>
    </a>
    </li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic