看起来应该很简单(堆栈溢出流行语)
分类法存档taxonomy-my-taxonomy.php
, 我正在使用 $terms = get_the_terms($post->ID, \'my-taxonomy\');
获取存档项的属性。
问题是这是后期术语,而不是归档术语。
它假设$post->ID
存在,即此分类法有帖子。我想显示带有各种术语属性的页面,即使它是空的。
怎样
看起来应该很简单(堆栈溢出流行语)
分类法存档taxonomy-my-taxonomy.php
, 我正在使用 $terms = get_the_terms($post->ID, \'my-taxonomy\');
获取存档项的属性。
问题是这是后期术语,而不是归档术语。
它假设$post->ID
存在,即此分类法有帖子。我想显示带有各种术语属性的页面,即使它是空的。
怎样
您只需检查帖子是否存在。否则,您可以获取当前查看的术语:
// Check if we have posts to work with
if( ! have_posts() ) {
$term = get_queried_object(); // Get the current term
}
// Check if we have a term to work with
if( ! empty( $term ) ) {
echo $term->name; // Output term properties
}
由于您在分类法模板中使用了此选项,get_queried_object()
应返回WP\\u Term对象。我有一个自定义的分类页面,它也有一个向上的滑块。问题是滑块显示来自所有分类法而非当前分类法的随机帖子。是否有办法过滤滑块中的图像,使其仅使用当前分类法?<?php global $taxonomy_location_url, $taxonomy_profile_url; $args = array( \'post_type\' => $taxonomy_profile_url, \'orderby\' => \'rand\', \'meta_que