2017-02-20 93 views
0

我希望能夠通過刪除read more鏈接自定義the_excerpt輸出,但前提是它位於小部件內部。WordPress:自定義部件內的摘錄

使用的情況是這樣的:

在我的網站,用戶可以發佈他們的旅行報告。我以兩種方式顯示這些報告 - PublishedFuturePublished列表報告出現在我不想在excerpt中進行任何更改的頁面,但Future帖子出現在自定義插件的側欄中。我想要excerpt這裏,但沒有連接到它的read more鏈接。

以下功能functions.php刪除read more鏈接通過檢查post_type,但從無處不在!我希望這個鏈接在普通列表中可見。

function custom_excerpt_more_link($more){ 
     global $post; 
     if($post->post_type == 'travelog') { 
      return '..'; 
     } else { 
      return '<a href="' . get_the_permalink() . '" rel="nofollow">&nbsp;[more]</a>'; 
     } 
    } 

是否有一個選項,會告訴WordPress的冒了出來只有當excerpt正在呈現一個小工具裏面這個鏈接?

希望以下屏幕截圖可能有助於解釋我正在嘗試完成的工作。

enter image description here

excerpt與標題後我第一次白色聖誕 - 2013年12月至馬拉里之旅應該有read more鏈接,而我不希望它爲那些在右側欄中列出。這可能嗎?

UPDATE:
修改後的代碼:

function custom_excerpt_more_link($more){ 
     if(dynamic_sidebar('upcoming-stories-sidebar')) { 
      global $post; 
      if ($post->post_type == 'travelog') { 
       return '..'; 
      } else { 
       return '<a href="' . get_the_permalink() . '" rel="nofollow">&nbsp;[more]</a>'; 
      } 
     } 
     else { 
      return '<a href="' . get_the_permalink() . '" rel="nofollow">&nbsp;[more]</a>'; 
     } 
    } 

    add_filter('excerpt_more', 'custom_excerpt_more_link'); 

截圖: enter image description here

回答

0

如果使用CSS顯示性能沒有這將是更好。首先找到後包裝;假設自定義帖子類型的包裝爲.custom,其CSS將爲

.custom a { 
    display:none 
} 
+0

感謝您的回覆。代碼實際上在我的內容區域內創建了無限循環的即將到來的故事!側欄不可見。用新的截圖和更新的代碼編輯我的文章。 –

+0

您正在使用什麼插件或代碼來生成側邊欄發佈內容? –

+0

我沒有使用任何現成的插件。這是一個使用WP_Query的自定義插件:'$ q = new WP_Query(array( 'post_type'=>'travelog', 'posts_per_page'=> 6, 'orderby'=>'date', 'post_status'=> array('future') ));' –