我正在开发一个wordpress主题,并想要显示一个名为'Artikel'的特定类别的帖子。但是,我的代码无效。这是我的代码:
<?php
$custom_query = new WP_Query([
'cat' => 'Artikel',
]);
if ($custom_query->have_posts()) {
while ($custom_query->have_posts()) {
$custom_query->the_post(); ?>
/* do things */
<?php
}
wp_reset_postdata();
}
?>
有谁知道我错过了什么?
答案 0 :(得分:0)
使用的类别ID未使用类别名称
$category_id=1;
$custom_query = new WP_Query([
'post_type' => 'post','posts_per_page' => -1,'order' => 'ASC','cat' => $category_id
]);
答案 1 :(得分:0)
我会这样做:
<?php
$args = array(
post_type => 'post',
'category_name' => 'Artikel',
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'ASC'
);
$custom_query = new WP_Query($args);
if ($custom_query->have_posts()) {
while ($custom_query->have_posts()) {
$custom_query->the_post();
[etc.]
?>
答案 2 :(得分:0)
请使用此代码显示特定类别的帖子。
<?php $args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' =>'4',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'name',
'terms' => 'Artikel'
),
),
);
$the_query = new WP_Query( $args ); ?>