php - wordpress custom - add class to the first blog -
here blog page template:
<?php /** * template name: blog * * standard blog template, create static page blog , select template. * * "template name:" bit above allows selectable * dropdown menu on edit page screen. */ get_header(); ?> <div id="main_container"> <!-- ie7 float fix --><!--[if lt ie 7]><span class="iefix">.</span><![endif]--> <div class="main"> <div class="entries_full"> <div class="entry_full"> <div class="box_twothirds mt30 pr60"> <!-- blog posts begin --> <?php $exclude_cat = get_option('bb_exclude_cat'); $exclude_temp = str_replace(",", ",-", $exclude_cat); $exclude_cats = "-" . $exclude_temp; $blog_posts = get_option('bb_blog_posts'); if($blog_posts == null) {$blog_posts = '5';} $temp = $wp_query; $wp_query= null; $wp_query = new wp_query('cat=' . $exclude_cats . '&paged=' . $paged . '&showposts=' . $blog_posts); $count = 0; while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <div class="blog"> <!-- displays blog posts --> <?php $count++; if($count > 3) { $count = 1; } ?> <h3 class="<?php if($count > 1) echo "mt25 "; ?>mb12"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3> <?php if(get_post_meta($post->id, large_image_value, $single = true) != null || get_post_meta($post->id, fullsize_value, $single = true) != null) { ?> <div class="mag_blog"><!-- magnifying glass div --> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php if (get_post_meta($post->id, large_image_value, true) != null) {echo get_post_meta($post->id, large_image_value, $single = true);} else if (get_post_meta($post->id, fullsize_value, true) != null) {echo get_post_meta($post->id, fullsize_value, $single = true);} else {echo get_post_meta($post->id, accordion_image_value, true);} ?>&h=213&w=600&zc=1" alt="<?php the_title(); ?>" /></a> </div><!-- end magnifying glass div --> <?php } ?> <p class="meta"><span class="postdate"><?php the_time('f js, y') ?></span><span class="tags"><?php the_category(', '); ?></span><span class="comments"><a href="<?php the_permalink(); ?>#comments" title="comments"><?php comments_number('0 comments','1 comment','% comments'); ?></a></span></p> <?php global $more; $more = false; ?><?php the_content('<span>continue reading</span>'); ?><?php $more = true; ?> <div class="bar mt25 mb30"></div> <?php comments_template( '', true ); ?> </div> <?php endwhile; if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?> <?php /* display navigation next/previous pages when applicable */ ?> <?php if ( $wp_query->max_num_pages > 1 ) : ?> <?php next_posts_link( __( '← older posts', 'twentyten' ) ); ?> <?php previous_posts_link( __( 'newer posts →', 'twentyten' ) ); ?> <?php endif; ?> <?php } $wp_query = null; $wp_query = $temp; ?> <!-- blog posts end --> </div> <!-- begin sidebar --> <?php include('sidebar.php'); ?> <!-- end sidebar --> <div class="clear"></div> </div><!-- end div.entry --> </div><!-- end div.entries --> <div class="clear"></div> </div><!-- end div#main --> <div class="clear"></div> </div><!-- end div#main_container--> <?php get_footer(); ?> </code>
just wonder if there way add class first blog item, or way make first block item has different style rest... or need edit on other php file?
thanks guys.
you can within first line of while() loop:
replace:
<div class="blog">
with:
<div class="blog<?php if ($count === 0) echo " first_post"; ?>">
that should add custom class first blog item on page called 'first_post'.
Comments
Post a Comment