• I would like to add a unique id to the first post so that I can add a bit of margin-top to that one only.

    Thanks

    Martin

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php $c = 0;
    if (have_posts()) : while (have_posts()) : the_post()
    ;$c++;
    if( $c == 1 ) $my_id = ' id="first"';
    else $my_id = ''; ?>
    
    <div <?php post_class();?><?php echo $my_id;?>">
    <h2 class="post-title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php _e('Post');?> <?php the_ID(); ?> - <?php _e('permanent link');?>"><?php the_title();?></a></h2>
    Thread Starter martcol

    (@hotmale)

    Thank you esmi,

    For helping me with that.

    I had to chop it about a bit (I think) to make it fit my category.php template and this is how it ended up.

    <?php $c = 0;
    		if (have_posts()) : while (have_posts()) : the_post()
    			;$c++;
    		if( $c == 1 ) $my_id = ' id="first"';
    			else $my_id = ''; ?>
    <?php if ( in_category('3') ) { ?>
               <div class="post-cat-three"<?php echo $my_id;?> >
     <?php } else { ?>
               <div class="post" <?php echo $my_id;?>>
     <?php } ?>
     <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

    Did I do anything wrong?

    Looks OK to me. Is it working?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add unique id to only first post’ is closed to new replies.