• Resolved lungemark

    (@lungemark)


    Hey WordPresspeople,
    i have a question, I’d like to display 4 posts on my index.php with all posts styled a little differently. How do i do this? simply adding an ID to the posts won’t work.

    So far i’ve tried

    <?php query_posts('showposts=1'); ?>
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    (...) rest of the loop
    <?php endwhile; endif; ?>
    <?php query_post('showposts=2&offset=1'); ?>
    < if have, while, the post >
    Rest of the code where the_content was in a div with a different id

    But that doesn’t do anything (Probably code for an older version of wordpress, this code came from a tutorial/blogpost i googled.)

    I’ve also tried styling the posts per category which works but you have to add an extra tag (Featured1, Featured2)
    I’d like to have “posted in: Web” in the blogpost
    What i’m trying to ask is how do i exclude one of the tags. (only show Web, Logo and leave “Feat1” out of the <?php the_category(‘, ‘); ?> -List.

    Thanks in advance!
    -Mark

Viewing 2 replies - 1 through 2 (of 2 total)
  • easy way to style them differently is to add a class to them and then hit them with CSS.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php static $count = 0;
    if ($count == "4") { break; }
    else { ?>
    
            <div class="post mypost<?php echo $count; ?>">
     		<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
     		<div class="entry">
       		<?php the_content(); ?>
            <?php echo "<b>" . $count . "</b>"; ?>
     		</div>
     		</div>
    
    <?php $count++; } ?>
    <?php endwhile; ?>
    <?php endif; ?>

    This will show 4 posts. It will give them a class of mypost0, mypost1, mypost2, mypost3 respectively. Then in your CSS you can simply do things like:

    .mypost0 {
    background: #eee;
    }
    
    .mypost1 {
    background: #e99;
    }
    
    .mypost2 {
    background: #9dd;
    }
    
    .mypost3 {
    background: #f66;
    }

    Thread Starter lungemark

    (@lungemark)

    Haha, dude you’re a lifesaver!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Post styling and/or loop Question’ is closed to new replies.