Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

iam working on my first wp theme and iam new to php and wordpress. i need to create a single category widget that displays at least five posts from specific category. inside this post loop i need a conditional function to make the first post different from the rest. to be clear iam using a plugin that gives me all the needed option except conditional function that makes the first post different from the others. is there any one could help me By editing the plugin file to add this conditional function . or showing me the entire code from scratch.thanks

share|improve this question

2 Answers 2

up vote 0 down vote accepted

To make the first post different you could add a post counter and change the output on the first loop.

$counter = 0
while ( $cat_posts->have_posts() ) {
$cat_posts->the_post();
    $counter++;

 if ( $counter == 0 ) {

 // Out put the different loop

}

  //Normal loop output
share|improve this answer
    
thanx Chris that's exactly what I meant .i tested it and works for me –  mahmoud sami Oct 30 '11 at 21:15

There isn't much code to this plugin, main output is done by pretty straightforward loop.

Unfortunately plugin gives no way to control styling of individual items so you will have to either:

  • fork it and edit to output class for styling for first item alone

  • try to make use of CSS for styling of existing markup (:first-child if I am not mistaken)

share|improve this answer
    
thanks Rarst . but i wanted it in the loop because iam going to display just the thumb in the first post.. –  mahmoud sami Oct 30 '11 at 21:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.