简体   繁体   English

如何根据Wordpress中的类别对数据进行排序?

[英]how could I sort the data based on categories in wordpress?

Being a newbie I am not able to know how to sort my posts based on categories which I have created in WordPress. 作为新手,我不知道如何根据我在WordPress中创建的类别对帖子进行排序。 I am getting my all posts because of the following code mentioned on image: 由于图像上提到了以下代码,因此我得到了所有帖子: 在此处输入图片说明

<?php $recent = new WP_Query(
"post_type=post&posts_per_page=6&orderby=date&order=DESC"); 
>

Navigation bar is my categories. 导航栏是我的类别。 So on clicking each category I should get posts relevant to that category only. 因此,在单击每个类别时,我应该只会获得与该类别相关的帖子。 For example clicking on Recipes, I should get all posts related to recipes only. 例如,单击“食谱”,我应该只获得与食谱有关的所有帖子。 Please suggest me plugins (jQuery) to give that tab the kind of functionality and how I am gonna implement this sort or filter sort of functionality in WordPress. 请建议我使用插件(jQuery),为该标签提供功能类型以及如何在WordPress中实现此类功能或过滤功能。 Please help me with some code. 请帮我一些代码。 Any help would be appreciated. 任何帮助,将不胜感激。

For best of my knowledge and if I m guessing you right. 据我所知,如果我猜对了。 make category.php(For wordpress post) or taxonomy.php(for custom post type taxonomy) 制作category.php(用于wordpress发布)或taxonomy.php(用于自定义帖子类型分类)

如何将类别添加为菜单。

try this: 尝试这个:

$wpq = array( 
    'orderby' => 'date',
    'order' => 'DESC',
    'posts_per_page' => 6,
    'post_type' => 'post',
    'taxonomy' => 'category', 
    'term' => 'category-slug' 
);
$recent = new WP_Query ($wpq);

NOTE: change 'category-slug' with correct Category slug 注意:用正确的类别子弹更改“类别子弹”

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

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