仔细查看blow代码-
$query_args = array(
\'posts_per_page\' => \'5\',
\'orderby\' => \'post_date\',
\'order\' => \'DESC\',
);
$listedPosts = new WP_Query($query_args);
// the loop
if ( $listedPosts->have_posts() ) {
while ( $listedPosts->have_posts() ) {
$listedPosts->the_post();
if ( (int) $listedPosts->current_post == 5 ) { // You need to use \'==\' or \'===\' for comparison.
// change the drop down field item to "Visible" from Invisible
} else {
// stay as is
}
}
}
以及-
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
当您在
taxonomy.php
页码或
archive.php
页在里面
single.php
获取分类术语的页面您需要使用以下代码-
For inside a loop-
//Do something if a specific array value exists within a post
$term_list = wp_get_post_terms(get_the_ID(), \'taxonomy _name\', array("fields" => "all"));
foreach($term_list as $term_single) {
echo $term_single->slug; //do something here
}
For outside of the loop-
//Do something if a specific array value exists within a post
$term_list = wp_get_post_terms($post->ID, \'product_features\', array("fields" => "all"));
foreach($term_list as $term_single) {
echo $term_single->slug; //do something here
}
希望这有帮助。