logo

$10
Pre-Defined CSS ID's for Most Recent Posts

I'm not sure how to word what I want.

This is what I have:

<ul id="dock">
<?php
$dock = new WP_Query();
$dock->query( 'showposts=5' );
while( $dock->have_posts() ) : $dock->the_post();
?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<img src="<?php bloginfo( 'template_directory' ); ?>/imgsize.php?w=69&h=54&img=<?php echo get_post_meta( $post->ID, "image_value", true ); ?>" alt="<?php the_title(); ?>" />
</a>
<span><?php the_title(); ?></span>
</li>
<?php
endwhile;
?>
</ul>



Which gives me this for output:

<ul id="dock">
<li>
<a href="#"....>
<img src="#".... />
</a>
<span>Post Title</span>
</li>
<li>
<a href="#"....>
<img src="#".... />
</a>
<span>Post Title</span>
</li>
<li>
<a href="#"....>
<img src="#".... />
</a>
<span>Post Title</span>
</li>
<li>
<a href="#"....>
<img src="#".... />
</a>
<span>Post Title</span>
</li>
<li>
<a href="#"....>
<img src="#".... />
</a>
<span>Post Title</span>
</li>
</ul>


as expected.


ALL I WANT is for the output to add a "pre-defined" id to each
<li>
tag.

IE:

<li id="positionA"><a href="#"><img src="#"><span>SPAN</span></li>
<li id="positionB"><a href="#"><img src="#"><span>SPAN</span></li>
<li id="positionC"><a href="#"><img src="#"><span>SPAN</span></li>
<li id="positionD"><a href="#"><img src="#"><span>SPAN</span></li>
<li id="positionE"><a href="#"><img src="#"><span>SPAN</span></li>


The most recent 5 posts will always be called, and the most recent post must always be "positionA," while the 5th most recent post must always be "positionE."

Thanks in advance.

Tim Greenwood | 05/19/10 at 11:59pm | Edit


(3) Possible Answers Submitted...

  • avatar
    Last edited:
    05/20/10
    12:15am
    Monster Coder says:

    <ul id="dock">

    <?php

    $dock = new WP_Query();

    $dock->query( 'showposts=5' );
    $pos = array('A','B','C','D','E');
    $i=0;
    while( $dock->have_posts() ) : $dock->the_post();

    ?>

    <li id="position<?php echo $pos[$i]; ?>">

    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">

    <img src="<?php bloginfo( 'template_directory' ); ?>/imgsize.php?w=69&h=54&img=<?php echo get_post_meta( $post->ID, "image_value", true ); ?>" alt="<?php the_title(); ?>" />

    </a>

    <span><?php the_title(); ?></span>

    </li>

    <?php
    $i++;

    endwhile;

    ?>

    </ul>

    Previous versions of this answer: 05/20/10 at 12:11am

    • 05/20/10 12:19am

      Tim Greenwood says:

      This is the one, works perfect. Thanks so much. Fast and dead on.

  • avatar
    Last edited:
    05/20/10
    12:13am
    Lew Ayotte says:

    In your wordpress loop do something like this:


    <?php if (have_posts()) : ?>
    <?php while(have_posts()) : the_post(); ?>
    <?php

    $i = 1;
    if ($i <= 5) {
    ?>
    <li id="position<?php echo $i; ?>"><a href="#"><img src="#"><span>SPAN</span></li>
    <?php
    $i++;
    }

    //other stuff

    <?php endwhile; ?>
    <?php endif; ?>

    Previous versions of this answer: 05/20/10 at 12:12am | 05/20/10 at 12:13am

  • avatar
    Last edited:
    05/20/10
    12:19am
    Roberto Mas says:


    <ul id="dock">
    <?php
    $count = 0
    $dock = new WP_Query();
    $dock->query( 'showposts=5' );
    while( $dock->have_posts() ) : $dock->the_post();
    $count ++
    ?>

    <li id="position<?php echo $count ?>">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <img src="<?php bloginfo( 'template_directory' ); ?>/imgsize.php?w=69&h=54&img=<?php echo get_post_meta( $post->ID, "image_value", true ); ?>" alt="<?php the_title(); ?>" />
    </a>
    <span><?php the_title(); ?></span>
    </li>

    <?php
    endwhile;
    ?>
    </ul>

    Previous versions of this answer: 05/20/10 at 12:18am | 05/20/10 at 12:19am

This question has expired.





Current status of this question: Completed