2015-11-09 27 views
2

我有一個自定義帖子類型的列表(shown as a grid by this plugin),但我需要一個分類值下的鏈接指向內部頁面。根據分類選項禁用自定義帖子類型鏈接

實施例:我有分類學 「例如」 與3個選項(OptionA - OptionB - 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

回答

1

解決方案(使用一點JQuery)。

第一步: 添加術語段塞作爲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> 

任何改善將受到歡迎

2

您可以查詢分類爲後,然後檢查,看看您的自定義後類型是它返回數組中:

$post_types = get_object_taxonomies($post); 

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

我試過,但它也由$ post_orders querys,我不知道怎麼加都,它打破了網頁。 –

+0

你可以粘貼整個文件,以便我更好地瞭解發生了什麼? –

+0

好吧,有一個大文件,但我會編輯我的文章,這樣你就可以看到它。 –

相關問題