WordPress.org

Ready to get started?Download WordPress

Forums

How do I get category.php to show children excerpts? (5 posts)

  1. FionaGilbert
    Member
    Posted 4 years ago #

    Hi all and good morning.

    I am using the following code to pull in a specific categories post

    http://paste-it.net/public/ce09af5/

    but I wondered if anyone could offer a way to filter this just to show a specific category child.

    Can anyone offer any advice as to what I need to add to my code please?

    Thanks,
    Fiona

  2. MichaelH
    Member
    Posted 4 years ago #

    You'd have to use get_categories('child_of='.get_query_var('cat')) to get whatever child category then use that in your query.

  3. FionaGilbert
    Member
    Posted 4 years ago #

    Thanks for that Michael,

    Is there anyone who could possibly show me how to implement in my code? I didn't code this - my 'ex' did and he's not around now!

    Thank you,
    Fiona

  4. MichaelH
    Member
    Posted 4 years ago #

    Maybe it is simpler than I presented. Try about this:

    <?php
    $cat_id = get_cat_ID('your child category name here');
    $args=array(
      'cat' => $cat_id,
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'Child category excerpts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_excerpt();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  5. FionaGilbert
    Member
    Posted 4 years ago #

    Sorry was away.

    Thank you so much. Will try this out tonight :)

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags