Dividing the loop to style post differently?

I’m using a plugin that displays post and shows them in a certain area on my site, such as the sidebar or anywhere i put the <?php;?> code, but only if the author that is writing the post clicks the check box in the new post window.

The plugin comes with an options page that allows me to set how many post to display.

Here is the code in the plugin that displays the post.

<?php
	
	$m_slider_sort = get_option('sort'); if(empty($c_slider_sort))    {$c_slider_sort = "post_date";}
	$m_slider_order = get_option('order'); if(empty($c_slider_order)){$c_slider_order = "DESC";}
	$m_slider_post_limit = get_option('limit_posts'); if(empty($m_slider_limit_posts)){$m_slider_limit_posts = "-1";}
            
	global $wpdb;

	global $post;
	
	$args = array( 'meta_key' => 'feat_music', 'meta_value'=> '1', 'suppress_filters' => 0, 'post_type' => array('post', 'page'), 'orderby' => $m_slider_sort, 'order' => $m_slider_order, 'numberposts'=> $m_slider_post_limit);
	
	$myposts = get_posts( $args );
	
	foreach( $myposts as $post ) :	setup_postdata($post);
		
		$m_slider_custom = get_post_custom($post->ID);
		
		$m_slider_thumb = m_slider_get_thumb("featmusic");
		
	?>

***HTML/PHP THE TITLE GOES HERE***

<?php endforeach; ?>	

I will be showing seven post. I want the first post to be styled differently than the next six post. Does anyone have any idea as to how to alter the code above so that I can style the first post differently from the next 6 post.

Also this line $m_slider_thumb = m_slider_get_thumb("featmusic"); grabs the thumbnail for the post but I need two of them, one for the first post and another for the next six post. This part of php coding I am not familiar with.

there must be a code between foreach ... enforeach which displays the post. maybe you let a counter run and style your post depending on this.

Yes, I’d do something like this:

$myposts = get_posts( $args );
$first = true; // set the flag to show the first pass through the loop
	
foreach( $myposts as $post ) :	setup_postdata($post);
		
  $m_slider_custom = get_post_custom($post->ID);
		
  $m_slider_thumb = m_slider_get_thumb("featmusic");
		
  if ($first) { 
    // do the stuff for the first entry 
    } else {
    // do the stuff for the other entries 
    } // end of else clause
  $first = false; // reset the flag for all subsequent passes
  endforeach; 
?>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.