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.

I left ????? where I need the answer.

<?php

global $post;

$the_post_ID = $post->ID;

$n = get_posts();
?>


<?php foreach ( $n as $post ) : ?>

<nav id="postNav">

<ul>
    <li<?php if (?????) echo ' class="current"'; ?>>
        <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten`enter code here`' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
    </li></ul>

<?php endforeach; ?>
share|improve this question
add comment

1 Answer

You can get first item using this code

<?php

global $post;

$the_post_ID = $post->ID;

$n = get_posts();
$i=1;
?>


<?php foreach ( $n as $post ) : ?>

<nav id="postNav">

<ul>
<li<?php if ($i){ echo ' class="current"'; $i=0; }?>>
    <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__(     'Permalink to %s', 'twentyten`enter code here`' ), the_title_attribute( 'echo=0'         ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
   </li></ul>

<?php endforeach; ?>
share|improve this answer
    
<li<?php if ($n[0]) echo ' class="current"'; ?>> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a> </li> this doesnt work –  user1355485 Feb 27 '13 at 7:05
    
Whats is it displaying? –  Vinod Dalvi Feb 27 '13 at 7:08
    
if i do if ($n[0]) add class; it just adds the class to all posts im just trying to do is add a class to the first post i just dont know what to write in the ???? part of my code I posted. Any help would be greatful –  user1355485 Feb 27 '13 at 7:12
    
Use the above updated code. –  Vinod Dalvi Feb 27 '13 at 7:16
    
It doesn't make total sense to me But it works Perfectly!!! Thanks your a life saver. –  user1355485 Feb 27 '13 at 7:23
add comment

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.