您可以这样做:
$args = array(
\'post_type\' => \'post_type_name\', // or use default if you use standard
\'numberposts\' => 3, // or you can use 1 if you need only from last post.
\'orderby\' => \'date\', //by dates to get lastest
\'order\' => \'DESC\',
);
$posts = get_posts($args);
$recent_taxonomies = [];
foreach ($posts as $key => $post_data) {
$recent_taxonomies[] = get_the_terms( $post_data->ID, \'custom_taxonomy_name\');
}
更多关于
get_posts
https://codex.wordpress.org/Template_Tags/get_posts更多关于
get_the_terms
https://developer.wordpress.org/reference/functions/get_the_terms/如果您想从此创建云标记,可以基于返回的对象和count
对于每个对象,然后基于它创建云。
为了简单地标记您可以使用的云(其中$name
是一个分类名称(它从整个分类中创建云)
function tagsCloudByTerm($name){
$tags_out = null;
$tax_terms = get_terms($name);
$tags_out = \'<span class="tag-meta ">\';
$tmp = [];
$max = 0;
if(!empty($tax_terms)):
foreach ($tax_terms as $term) :
if($max < $term->count){
$max = $term->count;
}
endforeach;
foreach ($tax_terms as $term) :
$percent = floor(($term->count / $max) * 100);
if ($percent < 20):
$class = \'smallest\';
elseif ($percent >= 20 and $percent < 40):
$class = \'small\';
elseif ($percent >= 40 and $percent < 60):
$class = \'medium\';
elseif ($percent >= 60 and $percent < 80):
$class = \'large\';
else:
$class = \'largest\';
endif;
$term_link_url = get_term_link($term, $post_taxonomies[$tag_key]);
$tmp[] = \'<a class="\'.$class.\'" href="\'.$term_link_url.\'" title="\'.$term->name.\'">\'.$term->name.\'</a>\';
endforeach;
endif;
$tags_out .= implode(\', \', $tmp);
unset($tmp);
$tags_out = $tags_out.\'</span>\';
return $tags_out ;
}