2014-04-02 45 views
0

我已經嘗試了很多事情,但我沒有得到更多linkparagraph如何添加更多在WordPress

page.php文件

<?php 
$args = array('post_type' => 'post', 'posts_per_page' => 10); 
$loop = new WP_Query($args); 
while ($loop->have_posts()) : $loop->the_post(); 
    echo '<div class="inner-box-post">'; 
    echo '<h2><a href="get_permalink();">'; 
    the_title(); 
    echo '</a></h2>'; 
    echo '<div class="thumbnail">'; 
     the_post_thumbnail('thumbnail'); 
     get_comments($args); 
    echo '</div>'; 
    echo '<div class="post-containt">'; 
    echo '<div class="post-date"><strong>'; 
    echo get_the_date(); 
    echo '</strong> </div>'; 
    echo the_excerpt(); ; 
    echo '</div> '; 
    echo '</div>'; 
    endwhile; ?> 
</div> 

function.php

function new_excerpt_more($output) { 
    return $output . '<p><a href="'. get_permalink() . '">' . 'Read more &raquo' . '</a></p>'; 
} 
add_filter('get_the_excerpt', 'new_excerpt_more'); 
+0

您的代碼中不需要大量的'echo'。只需正確使用打開和關閉php標籤。 –

回答

1

過濾器是excerpt_more,

add_filter('excerpt_more', 'new_excerpt_more'); 

Reference

+0

但''因'摘錄'顯示。那我該如何刪除它? –

1
<?php 
      $args = array('post_type' => 'post', 'posts_per_page' => 10); 
      $loop = new WP_Query($args); 
       while ($loop->have_posts()) : $loop->the_post(); 
    ?> 
     <div class="inner-box-post"> 
      <h2><a href="get_permalink();"><?php the_title(); ?></a></h2> 

      <div class="thumbnail"> 
       <?php the_post_thumbnail('thumbnail'); ?> 
       <?php get_comments($args); ?> 
      </div> 

     <div class="post-containt"> 
      <div class="post-date"> 
       <strong><?php echo get_the_date(); ?></strong> 
      </div> 
      <?php the_excerpt(); ?> 
     </div> 
    </div> 
     <?php endwhile; ?> 

刪除[...],並添加更多的選擇使用

function new_excerpt_more($output) { 
    $output = rtrim($output,'[...]'); 
    return $output . '<p><a href="'. get_permalink() . '">' . 'Read more >>' . '</a></p>'; 

} 
add_filter('excerpt_more', 'new_excerpt_more'); 

enter image description here

+0

沒有變化.. !! @ravi –

+0

經過一些更改刪除並添加您的readmore鏈接 –

+0

它的工作但日期不顯示,爲什麼? –

1

這不是一個回答,只是更正

你真的不需要在您的代碼中過度使用echo。只需正確使用打開和關閉php標籤。而是使用這個。它還有助於提高可讀性

<?php 
$args = array('post_type' => 'post', 'posts_per_page' => 10); 
$loop = new WP_Query($args); 
while ($loop->have_posts()) : $loop->the_post(); 
?> 
    <div class="inner-box-post"> 
    <h2><a href="get_permalink();"><?php the_title(); ?></a></h2> 
    <div class="thumbnail"> 
     <?php the_post_thumbnail('thumbnail'); ?> 
    <?php get_comments($args); ?> 
    </div> 
    <div class="post-containt"> 
    <div class="post-date"><strong> 
    <?php get_the_date(); ?> 
    </strong> </div> 
    <?php the_excerpt(); ?> 
    </div> 
    </div> 
    <?php endwhile; ?> 
</div> 
+0

謝謝;它的主意:) –