views:

29

answers:

1

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

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  A: 

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.

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:

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>';
}
CD Sanchez
Let me try this and let you know if this works...
Matthew
This did not work... when I add this to the function the link that is generated links to the same page that the link is in.
Matthew
@Matthew: I'm not exactly sure what you mean. Could you add an example of a link that is generated, versus what you expect/want?
CD Sanchez
@Daniel here is the link where I want these links to live:http://www.holylandmoments.org/shows
Matthew
@Matthew: But where is an example of the 'Listen Now' link the code currently generates? Also, thanks, whoever downvoted me for no apparent reason :/.
CD Sanchez
@Daniel, since this site is live I don't want o keep up very long. I will repost the functions.php file so you can see what happens.
Matthew
@Matthew: Is the `$post` variable set? It might not be in the scope when it's called. Try checking if it exists and then printing out the result. You could always define that function in the archive template and use it directly.
CD Sanchez
In my archive template I have:<?php /* Run the loop to output the posts. * If you want to overload this in a child theme then include a file * called loop-index.php and that will be used instead. */ get_template_part( 'loop', 'archive' ); ?>
Matthew
So i'm not sure where else I can make sure this is being set
Matthew
@Matthew: Maybe if you add this as the first line to the `holylandmoments_comment_link` function: `global $post;`. I edited it into my answer so you can see.
CD Sanchez
@Daniel... great let me try this and I will get back to you.
Matthew
@Daniel... Thanks a lot the first edit worked just fine.
Matthew