[英]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.