阅读更多摘录wordpress

时间:2014-04-30 20:34:49

标签: wordpress hyperlink

我已经查看了与我的问题类似的其他帖子但我必须遗漏一些东西。 我已经在页面中添加了摘录:

[title size="2"]LATEST ARTICLES[/title]
[recent_posts columns="4" number_posts="12" cat_id="" thumbnail="yes"  excerpt="yes" title="yes"] [/recent_posts]

我正在尝试做两件事

  1. 设置摘录的长度
  2. 将其链接到文章(不一定是阅读更多链接,点很好)
  3. 我尝试手动将摘录添加到页面的摘录区域(屏幕选项),但这并没有覆盖Wordpress的内容。

    在我的function.php文件中我正在使用

    add_filter('the_excerpt', 'do_shortcode');
    

    有效,但当我尝试在下面添加其他代码时,它什么都不做。我是否需要修改其他rphp文件才能注册?

    `enter code here`function new_excerpt_more($more) {
    return '<a href="'. get_permalink($post->ID) . '">' . ' read on ..' . '</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
    
    function new_excerpt_length($length) {
    return 46;
    }
    add_filter('excerpt_length', 'new_excerpt_length');
    

1 个答案:

答案 0 :(得分:0)

我已使用以下代码(from the codex)获得了您想要的结果:

function custom_excerpt_length( $length ) {
  return 46;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

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