Answer the question
In order to leave comments, you need to log in
How to sort posts in wordpress category?
Hello!
There is a category.php file. It contains the following code:
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div class="content">
<h2 class="page-title"><?php printf( __( '%s', 'masteritca' ),single_cat_title( '', false )); ?></h2>
<div class="catalog-wrapper">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="catalog-item">
<div class="bestsellers-img">
<?php the_post_thumbnail(); ?>
</div>
<span class="bestsellers-name"><?php the_title(); ?></span>
<a href="<?php the_permalink(); ?>" class="bestsellers-price"><?php the_field( 'product_price'); ?></a>
</div>
<?php endwhile; endif;?>
<?php if(function_exists( 'wp_pagenavi')) { wp_pagenavi(); } ?>
</div>
</div>
<?php get_footer(); ?>
Answer the question
In order to leave comments, you need to log in
as an example, opened <?php query_posts('cat='.$cat_list.'&order=ASC'); ?> and closed, ASC was replaced with the desired
<?php
$category = get_the_category();
$cat_list = $category[0]->cat_ID;
?>
<?php query_posts('cat='.$cat_list.'&order=ASC'); ?>
<?php if (have_posts()): while (have_posts()): the_post(); ?>
<tr>
<td>
<?php the_post_thumbnail('full'); ?>
</td>
<td class="separator"> </td>
<td>
<?php the_content(); ?>
</td>
</tr>
<?php endwhile; endif; wp_reset_query(); ?>
You can also use functions.php:
function modify_category_query_order( $query ) {
if ( $query-> is_category()) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'modify_category_query_order' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question