2016-11-28 56 views
1

在我的WordPress網站,我使用下面的代碼迴路我的最新文章:如何將每個帖子的閱讀更多按鈕硬編碼到我的WordPress最新新聞循環中?

<?php 
    if (is_single()) : 
     the_title('<h1 class="entry-title">', '</h1>'); 
    else : 
     the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>'); 
    endif; 

    if ('post' === get_post_type()) : ?> 
    <div class="entry-meta"> 
     <?php blogtristan_posted_on(); ?> <span class="loopdivide"> | <span class="loop-time"><?php the_time('H:i');?></span> (GMT) 

    </div><!-- .entry-meta --> 
    <?php 
    endif; ?> 
</header><!-- .entry-header --> 

    <div class="entry-content"> 
    <?php 
$post = $post->post_content; /* or you can use get_the_title() */ 
$getlength = strlen($post); 
$thelength = 200; 
echo substr($post, 0, $thelength); 
if ($getlength > $thelength) echo "..."; 
?> 

如何添加一個簡單的「更多」按鈕,爲每個循環項目?

回答

1

請下面的代碼嘗試

if (strlen($getlength) > 200) { 
    echo '<a href="' . get_the_permalink(get_the_ID()) . '" title="">Read more</a>'; 
}else{ 
    echo $post; 
} 
相關問題