简体   繁体   中英

WordPress control both post order and number of posts in category.php

I have these two snippets, the first for displaying a customized post order via postMash:

<?php
$wp_query->set('orderby', 'menu_order');
$wp_query->set('order', 'ASC');
$wp_query->get_posts();
?>
<?php get_posts("orderby=menu_order&order=ASC"); ?>

and the second for retrieving a custom number of posts.

<?php
$myPosts = new WP_Query();
$myPosts->query('showposts=50');
while ($myPosts->have_posts()) : $myPosts->the_post();
?>

How do I combine them into one category.php ?

Here is my category.php with just the first snippet:

http://pastebin.com/J8L7crNL

I haven't used postMash before, but if I understand its documentation correctly, you can just compose your query with get_posts like this:

<?php  
    $args = array( 'numberposts' => 50, 'order'=> 'ASC', 'orderby' => 'menu_order' );
    $my_posts = get_posts( $args );
    foreach ($my_posts as $post) :  setup_postdata($post); 
        //loop action
    endforeach;
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM