0

My code theme archive.php is

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
 * If you want to override this in a child theme, then include a file
 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
 */
get_template_part( 'content', 'test' get_post_format() );
?>
<?php endwhile; ?>
<?php semplicemente_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>

So i want to change order from desc to acs , orderby date and post per page is 100.

I found it.

$args = ( array(
'order' => 'ASC',
'orderby' => 'date',
'posts_per_page' => '100',) );

So i put $args to get_post_format(), the_post() put nothing happen?

Any idea?

Thank for you help

0

2 Answers 2

0

You can use pre_get_posts in your functions file for this with the WP_Query order and orderby parameters.

function alter_query( $query ) {
    if ( $query->is_archive() && $query->is_main_query() && !is_admin()) {
        $query->set( 'posts_per_page', 100 );
    }
}
add_action( 'pre_get_posts', 'alter_query' );
1
  • 1
    Remember to check for !is_admin(). And you want to maybe check for date archives, is_date(). Remember, is_archive() returns true on category, taxonomy, author and tag pages Commented Apr 2, 2015 at 8:26
0

So thanks for your help. Now i pay more attention to functions.php so my old code have effectively.

/* Change page order */
add_filter( 'pre_get_posts' , 'my_change_order' );

function my_change_order( $query ) {

// Check if the query is for an archive

if($query->is_archive)

    // Query was for archive, then set order

    $query->set( 'order' , 'asc' );


// Return the query (else there's no more query, oops!)

return $query;

}
// Code no paging//
function no_nopaging($query) {
    if (is_date()) {
    $query->set('nopaging', 1);
    }
}

add_action('parse_query', 'no_nopaging');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.