简体   繁体   English

如何在Wordpress中添加到摘录的额外链接

[英]How to add an extra link to the excerpt in wordpress

I'm trying to get this link to look like this: 我正在尝试使此链接看起来像这样:

Comment on this show >> | 对此节目发表评论>> | Listen to this show >> 听此节目>>

Where "Comment on this show >>" gets populated properly with its permalink. 此处的“永久链接”正确填充了“对此节目的评论>>”。

"Listen to this show >>" link should be populated with that posts 'Listen Now' custom field value. “收听此节目>>”链接应填充为“立即收听”自定义字段值。

function holylandmoments_comment_link() {
return ' <a class="read-more-link" href="'. get_permalink() . '">' . __( 'Comment on this show &raquo;', 'holylandmoments-show' ) . '</a> &nbsp;|&nbsp; <a class="read-more-link" href="'. get_post_meta($post->ID, 'Audio File',true); . '">' . __( 'Listen to this episode &raquo;', 'holylandmoments' ) . '</a>';
}

Problem is I don't get the path to the custom field value of Listen Now to populate the second link... any ideas?? 问题是我没有获取“立即收听”的自定义字段值的路径来填充第二个链接...有什么想法吗?

The custom field value is a link to an audio file. 自定义字段值是指向音频文件的链接。 So for all posts that fall under the category shows there is a custom field named 'Audio File' the value of that field is: 因此,对于属于该类别显示的所有帖子,都有一个名为“音频文件”的自定义字段,该字段的值为:

http://www.mydomain.org/audio/sample.mp3 http://www.mydomain.org/audio/sample.mp3

So when the excerpt is called for archive pages to display I need two links to display one that points back to the post and another that points to the MP3 file. 因此,当摘录要求存档页面显示时,我需要两个链接来显示一个指向该帖子的链接,另一个指向MP3文件的链接。

So in my functions.php file I have the function above and then I call it with: 因此,在我的functions.php文件中,我具有上面的函数,然后使用以下命令进行调用:

function holylandmoments_custom_excerpt_more( $output ) {
if ( has_excerpt() && in_category( _x('devotionals', 'devotionals category slug', 'holylandmoments') ) &&! is_attachment() ) {
    $output .= holylandmoments_read_more_link();
}
else
if ( has_excerpt() && in_category( _x('shows', 'shows category slug', 'holylandmoments') ) &&! is_attachment() ) {
    $output .= holylandmoments_comment_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'holylandmoments_custom_excerpt_more' );

Thanks! 谢谢!

Matt 马特

You have an extra semicolon in there. 您在那里有多余的分号。

href="'. get_post_meta($post->ID, 'Listen Now',true); . '">'
                                                    ^

Change to: 改成:

href="'. get_post_meta($post->ID, 'Listen Now',true) . '">'

The $post variable may not be in the current scope, so try bringing in the global $post into it. $post变量可能不在当前范围内,因此请尝试将全局$post引入其中。

function holylandmoments_comment_link() {
   global $post;
   return ' <a class="read-more-link" href="'. get_permalink() . '">' . __( 'Comment on this show &raquo;', 'holylandmoments-show' ) . '</a> &nbsp;|&nbsp; <a class="read-more-link" href="'. get_post_meta($post->ID, 'Audio File',true); . '">' . __( 'Listen to this episode &raquo;', 'holylandmoments' ) . '</a>';
}

I believe the function the_ID() also returns the ID of the current post, so try the following if it the other one doesn't work: 我相信函数the_ID()也会返回当前帖子的ID,因此如果其他帖子不起作用,请尝试以下操作:

function holylandmoments_comment_link() {
   return ' <a class="read-more-link" href="'. get_permalink() . '">' . __( 'Comment on this show &raquo;', 'holylandmoments-show' ) . '</a> &nbsp;|&nbsp; <a class="read-more-link" href="'. get_post_meta(the_ID(), 'Audio File',true); . '">' . __( 'Listen to this episode &raquo;', 'holylandmoments' ) . '</a>';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM