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


Disable custom post type links depending on the taxonomy option

我有一个自定义帖子类型的列表(此插件显示为网格),但我需要一个分类法值下的列表才能有到内部页面的链接。

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

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

有没有什么方法可以使用PHP实现这一功能?

以下是PHP代码中添加标题链接的部分:

$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_types = get_object_taxonomies( $post );
if( in_array( 'your taxonomy name', $post_types )) {
    // Show link
}

解决方案(使用一点JQuery)

第一步:将术语slug添加为CSS类,这样我就可以区分不同的类,以便稍后使用JQuery进行自定义。

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

第二步:禁用已创建术语段塞类的链接。

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

任何改进都将受到的欢迎