treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Ordered lists with PHP? (Wordpress)

  • Overall what I'm trying to do is list the number of attachments (1, 2, etc) for each post on a page. When you click on a number, it will change the image. Pretty much like a slideshow. How would I go about adding the numbers in my loop or could this be better solved via jQuery?

    The reason I am not using OL's is because it outputs a period after the number which I absolutely do not want.

    Code (so far):
    <?php
    if( function_exists( 'attachments_get_attachments' ) )
    {
    $attachments = attachments_get_attachments();
    $total_attachments = count( $attachments );
    if( $total_attachments ) : ?>
    <ul class="process">
    <?php for( $i=0; $i<$total_attachments; $i++ ) : ?>
    <li><a href="<?php echo $attachments[$i]['location']; ?>"></a></li>
    <?php endfor; ?>
    </ul>
    <?php endif; ?>
    <?php } ?>


    Desired Output (view source HTML):
    <li><a href="http://domain.com/path/to/image1.png">1</a></li&gt;
    <li><a href="http://domain.com/path/to/image2.png">2</a></li&gt;
    <li><a href="http://domain.com/path/to/image3.png">3</a></li&gt;
  • Solution:
    <?php
    if( function_exists( 'attachments_get_attachments' ) )
    {
    $attachments = attachments_get_attachments();
    $total_attachments = count( $attachments );
    if( $total_attachments ) : ?>
    <ul class="process">
    <?php for( $i=0; $i<$total_attachments; $i++ ) : ?>
    <li><a href="<?php echo $attachments[$i]['location']; ?>"><?php echo $i+1; ?></a></li>
    <?php endfor; ?>
    </ul>
    <?php endif; ?>
    <?php } ?>