根据分类选项禁用自定义 post 类型链接

Disable custom post type links depending on the taxonomy option

我有一个自定义 Post 类型的列表 (shown as a grid by this plugin),但我需要一个分类值下的那些才能在内页上有一个 link。

示例: 我的分类法“示例”有 3 个选项(OptionA - 选项B - OptionC), 但我只希望 "OptionB" 下的那些有一个内部 link:

我知道通过 css 有一个解决方案(隐藏 links 样式),但我想保持整个站点没有 css 技巧。

有什么方法可以使用 PHP 实现此功能吗?

这是 PHP 代码中将 link 添加到标题的部分:

$output .= '<div class="pl-detailcnt">
    <h4 class="pl-title left-txt">';
    if (isset($this->pw_hide_date) && ($this->pw_hide_date=='off')){
    $output .= '<span class="pl-date">'. get_the_date($this->pw_date_format).'</span>';
    }
    $output .= '<a href="'. $post->link .'" target="'. $this->pw_link_target  .'">'. get_the_title().'</a></h4>
    </div>';

由于我无法按照@Dontfeedthecode 的建议添加整个代码(超过最大字符数),所以这里是:http://ideone.com/HeVfny

您可以查询 post 的分类法,然后检查您的自定义 post 类型是否在数组中 returns:

$post_types = get_object_taxonomies( $post );

if( in_array( 'your taxonomy name', $post_types )) {
    // Show link
}

解决方案(使用一点JQuery)。

第一步: 将 term-slug 添加为 CSS class,这样我就可以区分 class 以便稍后使用 JQuery 对其进行自定义。

<div class="add_your_random_class_here '.$term->slug.'">

第二步: 禁用创建了 term-slug class 的链接。

<script>
 jQuery(function() {
jQuery('.here-goes-your-new-based-slug-class').click(function(e){e.preventDefault();});
});
</script>

欢迎任何改进