Viewing 3 replies - 1 through 3 (of 3 total)
  • Usually you put that in your theme’s index.php, but with the help of the Template Hierarchy article, determine what Template is displaying your posts (e.g. theme’s index.php). Then edit that Template and add this code before The Loop.

    So using the WordPress Default theme’s wp-content/themes/default/index.php before this line:

    <?php if (have_posts()) : ?>

    Put this:

    <?php
    //replace events with your category
    $cat_id = get_cat_ID('events');
    $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() ) {
      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
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thread Starter jf80

    (@jf80)

    Thanks but that appears to just post the titles of the posts from the category – not the whole posts which is what I would like.

    Any ideas?

    This is the site: https://electriccoolbox.org.uk/

    Thanks.

    Change:
    endwhile;

    to

    endwhile;
    the_content();

    Review the template tag, the_content()

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display only posts from one category?’ is closed to new replies.