[WORDPRESS] How to apply Different Style for Different Posts in a Loop ?

Discussion in 'PHP' started by Saket, Mar 5, 2010.

  1. #1
    Hello everyone. I need a small help with wordpress and php codes. I
    have a featured posts slider on my homepage and here is the code for
    it -
    <?php
                $getcat = get_option('dynata_slider_category');
                if($getcat=="all" || $getcat=="All Categories"){ $querycat = ""; }
                else{ $querycat = "&category_name=" . $getcat; }
                ?>
                <ul>
                    <?php query_posts("showposts=3" . $querycat);?>
                    <?php while (have_posts()) : the_post(); ?>    
                        <li>
                        <?php if(get_post_custom_values("feature")){ ?>
                        <img src="/wp-content/uploads<?php $values =
    get_post_custom_values("feature"); echo $values[0]; ?>" alt="<?php
    the_title(); ?>"/>
                        <div><a href="<?php the_permalink() ?>"  title="Permanent Link to
    <?php the_title_attribute(); ?>">Read Full Article</a></div>
                        <div><?php the_title_attribute(); ?>"</div>
                        <?php } ?>
                        </li>
                      <?php endwhile; ?>
    
    Code (markup):
    but the problem is that in this loop, every post and its image appear at the same position as a slideshow.
    BUT What When I Want To Display Each Post With Different Style ? Like i want the featured posts to appear in 3 boxes. They all are not at the same place, so they each have different DIV style (position, padding, margin, left, right, z-index all are different for different box)
    So how do i add different DIV style in that code ?
     
    Saket, Mar 5, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    You have to write here full code. This part is not enough to help you.
     
    s_ruben, Mar 5, 2010 IP
  3. Saket

    Saket Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    what more do i need ? that part of code is enough i think because its the part where i am having problem. you don't need anything else in a wordpress file to show posts
     
    Saket, Mar 6, 2010 IP
  4. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #4
    OK, I will predict!!! :) I think you have to change the div id and add different ids for each post.
     
    s_ruben, Mar 6, 2010 IP
  5. Saket

    Saket Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hmmm ok i did it myself by adding a variable in the while loop which increases on every loop and used it in the div.
    By the way, Thanks s_ruben for sparing your time
     
    Saket, Mar 7, 2010 IP