WordPress.org

Forums

Pulling posts from certain category and applying different style to only first. (3 posts)

  1. bencharity
    Member
    Posted 5 years ago #

    If I want to pull only from a certain category, where would I put that call?

    Using this:

    <?php if (have_posts()) : ?>
    <?php $post = $posts[0]; $c=0;?>
    <?php while (have_posts()) : the_post(); ?>
    
    <?php $c++;
    if( $c == 1) :?>
    <h1>The first post on the main index page</h1>
    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    
    <?php else :?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php endif;?>
    
    <?php endwhile; ?>

    I was using this:

    <?php
    query_posts("cat=16");
    global $more;
    // set $more to 0 in order to only get the first part of the post
    $more = 0;
    ?>

    But obviously this lacks the style changes. Not sure how to combine...

    Thanks in advance

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Try:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'cat' => 16,
    	'paged' => $paged
    );
    query_posts($args);
    ?>
    <?php if (have_posts()) : ?>
    <?php $post = $posts[0]; $c=0;?>
    <?php while (have_posts()) : the_post(); ?>
    [...]
  3. bencharity
    Member
    Posted 5 years ago #

    Sorry, I'm still a bit new at this, how can I use what you have shared, and still have the first styled differently as in my example?

    Thanks again

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags