我正在使用 WordPress 和高级自定义字段。我为每个循环创建了一个,一切正常。但是我不希望显示具有“草稿”状态的帖子这也可以,但是如果帖子的数组长度等于或大于 4 个帖子,我想显示一个不同的 HTML 类“col-sm-6”但这不起作用。
基本上,如果帖子已发布且数组长度等于 4,则更改类,否则什么也不做。但由于某种原因,它没有按应有的方式工作。
有人可以帮我吗?
我的代码:
<?php
$posts = get_field('home_add_news');
$counter = 0;
if($posts):
?>
<section id="news">
<div class="container">
<div class="row">
<?php
foreach( $posts as $post):
$post_date = get_the_date( 'd M Y' );
$post_img_url = get_the_post_thumbnail_url($post->ID, 'full');
$post_categories = get_the_category( $post->ID );
$post_category = $post_categories[0]->cat_name;
$post_class = '';
if(has_category('nieuws')):
$post_class = 'news__block--image';
elseif(has_category('project')):
$post_class = 'news__block--primary';
elseif(has_category('proces')):
$post_class = 'news__block--secondary';
elseif(has_category('tijdlijn')):
$post_class = 'news__block--tertiary';
else:
$post_class = 'news__block--tertiary';
endif;
if ('publish' === $post->post_status):
$counter++;
?>
萧十郎