Отображать последние сообщения категории в обратном порядке - PullRequest
0 голосов
/ 07 октября 2019

Я использую этот код для отображения последних сообщений в теме. Но я хочу показать эти сообщения в обратном порядке.

как я могу это сделать?

<ul class="topics-list color-red-content">
  <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
      <li>
        <i class="far fa-circle"></i>
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
      </li>
    <?php endwhile; ?>
  <?php endif; ?>
</ul>

Ответы [ 3 ]

0 голосов
/ 07 октября 2019

Вы можете попробовать это. Добавьте этот код в ваш файл functions.php.

//function to modify default WordPress query
function wpb_custom_query( $query ) {

    // Make sure we only modify the main query on the homepage  
    if( $query->is_main_query() && ! is_admin() && $query->is_home() ) {

        // Set parameters to modify the query
        $query->set( 'orderby', 'date' );
        $query->set( 'order', 'ASC' );
    }
}

// Hook our custom query function to the pre_get_posts 
add_action( 'pre_get_posts', 'wpb_custom_query' );
0 голосов
/ 07 октября 2019

с этим кодом, загруженным

<?php
// the query
$wpb_all_query = new WP_Query(array('post_type' => 'post', 'cat' => '309', 'order' => 'ASC', 'orderby' => 'date', 'post_status' => 'publish', 'posts_per_page' => -1)); ?>

<?php if ($wpb_all_query->have_posts()) : ?>

    <ul>

        <!-- the loop -->
        <?php while ($wpb_all_query->have_posts()) : $wpb_all_query->the_post(); ?>
            <li>
                <i class="far fa-circle"></i>
                <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
            </li>
        <?php endwhile; ?>
        <!-- end of the loop -->

    </ul>

    <?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
0 голосов
/ 07 октября 2019

Вы можете добавить приведенный ниже код в начало вашего файла.

add_action('pre_get_posts', 'wpse_change_post_order');

function wpse_change_post_order($query){
    $query->set('order','ASC');
    $query->set('orderby','date');

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...