【问题标题】:Ellipses after excerpt AND "Read More"摘录和“阅读更多”后的省略号
【发布时间】:2019-02-21 09:03:15
【问题描述】:

我不知道如何同时拥有这两者;摘录后的 3 个点,结合“阅读更多”链接(但不是直接在省略号之后)。有一个插件可以做到这一点,但我宁愿避免将一个插件用于这么小的东西。

这是我现在正在使用的代码,以免干扰它。

首先,我将“阅读更多”改为“继续阅读”:

function new_excerpt_more($more) {
   global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Continue Reading...</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

然后,我添加了以下内容,以便可以使用水平线分隔每个条目:

add_filter( "the_excerpt", "add_class_to_excerpt" );
    function add_class_to_excerpt( $excerpt ) {
return str_replace('</p>', '</p><hr>', $excerpt);
}

我的“继续阅读”链接在它自己的行,摘录的右下角。我只想在摘录的最后一个词之后附加“...”。我发现最接近的是它的内容如下:

我不想要的:

Lorem Ipsum 只是印刷和排版行业的虚拟文本。 Lorem Ipsum 一直是业界的...继续阅读...

我想要什么:

以上,但将我的继续阅读留在自己的行上并向右浮动。

有什么想法吗?提前致谢, 特蕾西

--------已由 JAY 解决!!! 谢谢杰,这是我的更改(与我最初添加的代码的第一个 sn-p 相比:

   function new_excerpt_more($more) {
   global $post;
return '...<span><a class="moretag" href="'. get_permalink($post->ID) .      '"> Continue Reading...</a></span>';
 }
 add_filter('excerpt_more', 'new_excerpt_more');

【问题讨论】:

  • 把链接放到一个span中,把span向右浮动。
  • 杰伊!做到了!!!我已经让它向右浮动了。检查一下...我所做的只是在“返回”之后和链接之前添加 3 个点...还添加了 span 标签。这里是新的sn-p....好吧,这里不能贴了...我加到上面吧。

标签: php jquery wordpress function


【解决方案1】:

使用此过滤器:

function ellipses_excerpt_more( $output ) {
  if ( has_excerpt() && ! is_attachment() ) {
    $output .= '...';
  }
  return $output;
}
add_filter( 'get_the_excerpt', 'ellipses_excerpt_more', 1, 10 );

【讨论】:

  • 可悲的是,这在任何地方都没有区别;他们没有出现在任何地方。感谢您的回复!
  • 理论上它只有在你通过它的 getter 方法获取摘录时才有效,该方法应用 "get_the_excerpt" 过滤器,如 "get_the_excerpt()" 函数。您也可以尝试将过滤器注册的优先级修改为高于 10 的数字(这是默认值),以防其他插件覆盖我的 sn-p。 (我更新了我的答案,你会看到常数 10 ehich 是优先级,增加该值,即:90)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-14
  • 2013-03-12
  • 2018-09-09
  • 1970-01-01
  • 2017-04-04
  • 1970-01-01
  • 2012-03-02
相关资源
最近更新 更多