2014-12-20 23 views
3

這裏是我想做的事:WordPress的顯示更多的條目頁腳

我有我想只顯示到特定時間點的博客文章。所以在後我把

<!--more--> 

在正確的位置。

我content.php看起來是這樣的:

<div class="entry-content"> 
    <?php the_content('read more'); ?> 
</div><!-- .entry-content --> 

<footer class="entry-footer"> 
    <?php mytheme_entry_footer(); ?> 
</footer><!-- .entry-footer --> 

的「更多」鏈接獲取內容,它應該是右後顯示。但是,如何使用「註釋」鏈接將其顯示在輸入頁腳內?

是否有與解決方案摘錄?

<?php the_excerpt(); ?> 

我認爲這樣做會更好,因爲我不需要在每一篇文章中都加入這一行。

回答

2

可以刪除通過使用下面的過濾器「閱讀更多」您functions.php

add_filter('the_content_more_link', 'remove_more_link', 10, 2); 

function remove_more_link($more_link, $more_link_text) { 
    return; 
} 

現在,您可以創建入門頁腳中自己的閱讀更多鏈接:

<footer class="entry-footer"> 
    <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">Read more</a> 
    <?php mytheme_entry_footer(); ?> 
</footer><!-- .entry-footer --> 

編輯:

在下面的評論中提出了以下問題:

I used the_excerpt() instead of the_content(). Is it possible to only display the link if the post is actually too long?

您可以通過檢查摘錄是否與內容不同來做到這一點。如果是這樣的話(所以比摘錄更多的內容被顯示),可以顯示更多的鏈接:

<?php if (get_the_content() != get_the_excerpt()){ ?> 

    <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">Read more</a> 

<?php } ?> 
+0

這對我來說很好。我使用the_excerpt()而不是the_content()。 如果帖子實際上太長,是否可以只顯示鏈接? (超過55個字符) –

+1

@HansUllrich或許您可以檢查摘錄('get_the_excerpt()')的長度(等於內容的長度)('get_the_content()')。如果他們不同,你可以顯示閱讀更多鏈接。 – vicente

+0

好吧,如果我使條件get_the_excerpt()

0

我用一個解決辦法:

//REMOVE 'MORE' LINK AND HARDCODE IT INTO PAGE - TEASER JUST PLAIN ELLIPSIS 
function modify_read_more_link() { 
    if (is_front_page()) { 
     return '...'; 
    } else { 
     return '</div><footer class="clearfix"><a class="mg-read-more" href="' . get_permalink() . '">Continue Reading <i class="fa fa-long-arrow-right"></i></a>'; 
    } 
} 
add_filter('the_content_more_link', 'modify_read_more_link'); 

說明:頭版我有一個簡短的概述,只能在帖子標題中點擊。而對於博客一覽表(後在上面function.phpelse):

<article> 
 
    <header></header> 
 
    <div> 
 
    <?php the_content(); ?> 
 
    </footer> 
 
</article>

中,你可以看到失蹤div關閉和footer開放標籤。這有點messi,但它把原來的Wordpress Teaser帶入下一個分區。

謝謝你的閱讀。

相關問題