• Resolved Scribe

    (@scribe)


    I use version 2.3.1

    I’ve set up a page and want a list of post titles for only one child category to show on that page (not the parent or any other category). I know how to set up the page, but can’t work out the coding for the listing.

    For example: Parent Category is History. There are two child categories – Egyptian and Medieval. I want the titles of all the posts filed under Egyptian to show up on the page. And I need them to link to the post, of course.

    Can this be done? I’ve searched and searched through the documentation and support forums, but can’t find the right coding. Any advice will be much appreciated.

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Scribe

    (@scribe)

    I’ve tried a couple of things, but they don’t work.

    Example:

    <?php
    query_posts(‘cat=2’);
    ?>

    This causes a repetition on the page, which then crashes the page. Am I heading in the right direction? What am I doing wrong?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    This causes a repetition on the page, which then crashes the page.

    Errr… What? That doesn’t make any sense. What is a “repetition”? What do you mean by “crashes the page”? Those words just don’t make any sense in that particular order.

    A custom query_posts() call with a customized Loop is the correct answer here, of course.

    Thread Starter Scribe

    (@scribe)

    OK, I found a link to a page that gave me the following code. It works except it only shows 5 posts. How can I change the coding so that it shows all the posts?

    <?php $posts = get_posts( "category=2" ); ?>
    <?php if( $posts ) : ?> 
    
    <div class="section" id="egyptian">
    <h2>Egyptian</h2>
    <ul>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?> 
    
    <li><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li> 
    
    <?php endforeach; ?>
    </ul>
    </div> 
    
    <?php endif; ?>
    Thread Starter Scribe

    (@scribe)

    I figured it out myself. The following code lists all the posts (by title only) from one category on a page.

    <?php $posts = get_posts( "category=2&numberposts=100" ); ?>
    <?php if( $posts ) : ?> 
    
    <div class="section" id="egyptian">
    <h2>Egyptian</h2>
    <ul>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?> 
    
    <li><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li> 
    
    <?php endforeach; ?>
    </ul>
    </div> 
    
    <?php endif; ?>

    Now, I need to know how to exclude one post from this loop ie post id = 688. Any suggestions?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Now, I need to know how to exclude one post from this loop ie post id = 688. Any suggestions?

    get_posts( "category=2&numberposts=100&exclude=688" );

    Thread Starter Scribe

    (@scribe)

    All is working just fine now. Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Categories: List of Titles by Child Only’ is closed to new replies.