代码之家  ›  专栏  ›  技术社区  ›  Matrym

用Wordpress的摘录和“更多”链接?

  •  6
  • Matrym  · 技术社区  · 15 年前

    function new_excerpt_more($post) {
        return '<a href="'. get_permalink($post->ID) . '">' . 'Read the Rest...' . '</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
    

    依据: http://codex.wordpress.org/Function_Reference/the_excerpt

    但是当我将这个添加到functions.php中,并尝试使用它时,我没有看到更多链接。以下是我如何使用它:

    the_excerpt(__('(more...)'));
    

    我也试过:

    the_excerpt();
    

    更新:我尝试了以下操作,但它要么返回错误(如果没有参数),要么不显示任何摘录或任何内容(如果有参数):

    function new_excerpt_more($excerpt) {
        $link = get_permalink();
        $title = the_title('','',false);
        $ahref = '<a href="'.$link.'" title="'.$title.'">more...</a>';
        return str_replace('[...]', $ahref, $excerpt);
    }
    add_filter('wp_trim_excerpt', 'new_excerpt_more');
    
    5 回复  |  直到 13 年前
        1
  •  12
  •   Matrym    15 年前
    function new_excerpt_more($output) {
        return $output . '<p><a href="'. get_permalink() . '">' . 'Read the Rest...' . '</a></p>';
    }
    add_filter('get_the_excerpt', 'new_excerpt_more');
    

    <?php the_excerpt(); ?>
    
        2
  •  2
  •   azhar Vaibhav Patil    12 年前
    function new_excerpt_more( ) {
    return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">ReadMore</a>';
     }
    add_filter( 'excerpt_more', 'new_excerpt_more' );
    

    使用

    the_excerpt();
    
        3
  •  0
  •   gasoved    15 年前

    这应该是你要找的:

    function new_excerpt_more($excerpt) {
        $link = get_permalink();
        $title = the_title('','',false);
        $ahref = '<a href="'.$link.'" title="'.$title.'">more...</a>';
        return str_replace('[...]', $ahref, $excerpt);
    }
    add_filter('wp_trim_excerpt', 'new_excerpt_more');
    
        4
  •  0
  •   Jon    11 年前

    function new_excerpt_more( $more ) {
        return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read More</a>';
    }
    add_filter( 'excerpt_more', 'new_excerpt_more' );
    

    http://codex.wordpress.org/Function_Reference/the_excerpt#Remove_.5B....5D_string_using_Filters

        5
  •  -1
  •   Ian    15 年前

    我相信wordpress建议使用“the content()”而不是“the extract()”

        <?php  global $more;    
           $more = 0;
           the_content("Read the Rest of " . the_title('', '', false)); ?>