admin管理员组文章数量:1314514
I had a problem, I converted an html template to wordpress, now I want a section Category Enable to display content using categories Does anyone know the solution and code? iam use a code and not work for category :
<?php
$a = array(
'posts_per_page' =>200,
'offset' => 0,
'cat' => '',
'category_name' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'mahsulat',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true );
$the_query=new WP_Query($a);
while($the_query->have_posts())
{
$the_query->the_post();
?>
thank
I had a problem, I converted an html template to wordpress, now I want a section Category Enable to display content using categories Does anyone know the solution and code? iam use a code and not work for category :
<?php
$a = array(
'posts_per_page' =>200,
'offset' => 0,
'cat' => '',
'category_name' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'mahsulat',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true );
$the_query=new WP_Query($a);
while($the_query->have_posts())
{
$the_query->the_post();
?>
thank
Share Improve this question asked Nov 25, 2020 at 14:27 kasra abbaszadehkasra abbaszadeh 111 bronze badge1 Answer
Reset to default 1You should look at the WordPress Template Hierarchy. If you want to show an archive of your posts you create a template called archive-mahsulat.php
where mahsulat
is your post type. Then you can add a normal WordPress Loop to the file so it can output posts of that type.
If you're looking to create a category page for your post type you first need to register a taxonomy. Then you can create a archive page called taxonomy-{$taxonomy}.php
where {$taxonomy}
would be replaced with your specific taxonomy slug.
You don't need to create a custom secondary query for these things, if the PHP template pages exist and are named properly then WordPress will connect the dots and query the data for you.
本文标签: phpHow Display Posts on category
版权声明:本文标题:php - How Display Posts on category 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741964100a2407446.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论