• igralec

    (@igralec)


    I need help. How can I display category posts diferent.

    I need to display for every category (archive.php) something like this:

    First post display:

    <?php the_post_thumbnail(); ?>
    <?php the_title(); ?>
    <?php the_excerpt(); ?>

    Next 4 posts display:

    <?php the_post_thumbnail(); ?>
    <?php the_title(); ?>

    and the following posts display only:
    <?php the_title(); ?>

    and with navigation (next, previous) i do move true only last display posts (not first and next 4).

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael

    (@alchymyth)

    what theme are you using?

    general:

    you could try using a counter variable or the loop variable $wp_query->current_post to distinguish between the posts;

    example:

    <?php //start of the loop;
    if(have_posts()): while( have_posts() ) : the_post();
    
    if( $wp_query->current_post < 5 && !is_paged() ) the_post_thumbnail();
    the_title();
    if( $wp_query->current_post == 0 && !is_paged() ) the_excerpt(); 
    
    //end of the loop;
    endwhile; endif; ?>
    Thread Starter igralec

    (@igralec)

    I’m working with custom theme.

    How can i implement this code into my design.

    My code looks like this:

    <div class="header">
    <?php the_post_thumbnail(); ?>
    <h2><?php the_title(); ?></h2>
    <p><?php the_excerpt(); ?></p>
    </div>
    <div class="main">
    <?php the_post_thumbnail(); ?>
    <h2><?php the_title(); ?></h2>
    </div>
    <div class="footer">
    <h2><?php the_title(); ?></h2>
    </div>
    
    <div class="nav">
    <?php previous_posts_link('Previous') ?><?php next_posts_link('Next') ?><a href="<?php echo home_url(); ?>" class="selected">Home</a></div>

    and it need to be limit number of every item.
    header (1 post)
    main (next 4 posts)
    footer (next 10 posts) -> those are moving with navigation

    I did search for something like this for few times and i couldn’t find anything workable.

    Michael

    (@alchymyth)

    <?php if( $wp_query->current_post == 0 && !is_paged() ) : ?>
    <div class="header">
    <?php the_post_thumbnail(); ?>
    <h2><?php the_title(); ?></h2>
    <p><?php the_excerpt(); ?></p>
    </div>
    <?php elseif( $wp_query->current_post < 5 && !is_paged() ) : ?>
    <div class="main">
    <?php the_post_thumbnail(); ?>
    <h2><?php the_title(); ?></h2>
    </div>
    <?php else : ?>
    <div class="footer">
    <h2><?php the_title(); ?></h2>
    </div>
    <?php endif; ?>

    the only restriction with the above is that it always shows 15 posts per page;
    having a different number of posts just on the first page of the pagination would require a custom-made pagination which might be exceedingly complicated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display category posts with diferent components’ is closed to new replies.