繁体   English   中英

带有类别的 Wordpress 输出帖子

[英]Wordpress output posts with category

我有输出最后 3 个帖子的循环:

<?php
    $args = array( 'numberposts' => 3 );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
            /////////insert smth
<?php endforeach; ?>

我需要确保帖子类别等于“空缺”,我可以只过滤属于这个类别的帖子还是我必须使用 (if!=) ?

当然很简单: https : //codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

<?php
    $args = array( 'numberposts' => 3, 'category_name' => 'vakancy' );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
            /////////insert smth
<?php endforeach; ?>

暂无
暂无

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

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