简体   繁体   English

WordPress控制category.php中的发布顺序和发布数量

[英]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: 我有以下两个片段,第一个片段用于通过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 ? 如何将它们合并为一个category.php?

Here is my category.php with just the first snippet: 这是我的category.php,只有第一个代码段:

http://pastebin.com/J8L7crNL 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: 我以前没有使用过postMash,但是如果我正确理解了其文档,则可以使用get_posts编写查询,如下所示:

<?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;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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