WordPress.org

Ready to get started?Download WordPress

Forums

Descending Order? (3 posts)

  1. bradygo
    Member
    Posted 4 years ago #

    This is the code for my asides. Please help me figure out how to change this code to list posts in descending order. I worked on it a bit myself but I can't figure it out.

    <?php if ($posts) : foreach ($posts as $post) : the_post() ?>
    <?php if (in_category(109)) { ?>
    
    <div class="asides_sidebar">
    
                        <h3 style="padding:0 0 0px !important;margin: 0 0 5px 105px !important;text-indent: -105px; margin-top: 0; margin-bottom: 0;><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
    
    </div>
    <?php } ?>
    <?php endforeach; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    Try changing.

    <?php if ($posts) :

    to.

    <?php if ($posts) :
    ksort($posts); // Sort the array by key (shouldn't be required, but just incase)
    array_reverse($posts,true); // Reverse the array, preserving keys

    Or you might need to do it like this..

    <?php if ($posts) :
    $posts = ksort($posts); // Sort the array by key (shouldn't be required, but just incase)
    $posts = array_reverse($posts,true); // Reverse the array, preserving keys
  3. bradygo
    Member
    Posted 4 years ago #

    Thanks for the reply, but I couldnt get this work either. Frustrating....

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags