我试图让这个链接看起来像这样:
评论这个节目>> |听这个节目>>
其中“对此节目发表评论>>”正确填充其永久链接。
“听这个节目>>”链接应填充帖子“立即收听”自定义字段值。
function holylandmoments_comment_link() {
return ' <a class="read-more-link" href="'. get_permalink() . '">' . __( 'Comment on this show »', 'holylandmoments-show' ) . '</a> | <a class="read-more-link" href="'. get_post_meta($post->ID, 'Audio File',true); . '">' . __( 'Listen to this episode »', 'holylandmoments' ) . '</a>';
}
问题是我没有获得“立即收听”的自定义字段值的路径来填充第二个链接...有什么想法吗?
自定义字段值是音频文件的链接。因此,对于属于该类别的所有帖子,显示有一个名为“音频文件”的自定义字段,该字段的值是:
http://www.mydomain.org/audio/sample.mp3
因此,当调用摘录来显示存档页面时,我需要两个链接来显示一个指向帖子的链接,另一个链接指向 MP3 文件。
所以在我的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' );
谢谢!
马特
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 »', 'holylandmoments-show' ) . '</a> | <a class="read-more-link" href="'. get_post_meta($post->ID, 'Audio File',true); . '">' . __( 'Listen to this episode »', '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
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.
So in my functions.php file I have the function above and then I call it with:
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
发布评论
评论(1)
那里有一个额外的分号。
更改为:
$post
变量可能不在当前范围内,因此尝试将全局$post
引入其中。我相信函数
the_ID()
也会返回当前帖子的 ID,因此如果另一个函数不起作用,请尝试以下操作:You have an extra semicolon in there.
Change to:
The
$post
variable may not be in the current scope, so try bringing in the global$post
into it.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: