[英]Wordpress multiple categories by id, shows only first
i'am trying to publish 3 categories in 3 different rows, i use same code, just changing the category ID, but it shows only first category and it cut it self whole website bellow this code.我正在尝试在 3 个不同的行中发布 3 个类别,我使用相同的代码,只是更改了类别 ID,但它只显示第一个类别,并且它在此代码下方将整个网站剪断。 Can someone tell me please what i do wrong?
有人可以告诉我我做错了什么吗?
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'cat' => '1',
'posts_per_page' => 5,
'paged' => $paged,
);
$arr_posts = new WP_Query($args);
if ($arr_posts->have_posts()) :
while ($arr_posts->have_posts()) :
$arr_posts->the_post();
?>
<div class="col-sm-12 col-md-12 col-lg-12 news-box-list mt-2 mb-2">
<div class="row align-items-center">
<div class="col-sm-12 col-md-4 col-lg-4 col-xl-4">
<?php if (has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" alt="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail('post-thumbnail', ['class' => 'img-fluid rounded-4']); ?>
</a>
<?php endif; ?>
</div>
<div class="col-sm-12 col-md-8 col-lg-8 col-xl-8">
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
</div>
</div>
</div>
<?php
endwhile;
wp_pagenavi(
array(
'query' => $arr_posts,
)
);
endif;
?>
Fixed - in case someone would like to use exact code.已修复 - 以防有人想使用准确的代码。
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'cat' => '1',
'posts_per_page' => 5,
'paged' => $paged,
);
$arr_posts = new WP_Query($args);
if ($arr_posts->have_posts()) :
while ($arr_posts->have_posts()) :
$arr_posts->the_post();
?>
<div class="col-sm-12 col-md-12 col-lg-12 news-box-list mt-2 mb-2">
<div class="row align-items-center">
<div class="col-sm-12 col-md-4 col-lg-4 col-xl-4">
<?php if (has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" alt="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail('post-thumbnail', ['class' => 'img-fluid rounded-4']); ?>
</a>
<?php endif; ?>
</div>
<div class="col-sm-12 col-md-8 col-lg-8 col-xl-8">
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
</div>
</div>
</div>
<?php
endwhile;
endif;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.