Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Excerpt Issue - linkage WordPress

  • SOLVED

Hi everyone.

I am having issues with linking a 'read more' and a 'custom field' button through excerpt option. You can view a sample at the following:
http://thehelix.ie/web2011/index.php/whatson/

From this you can see that the plugin [amr events list] has pulled in the buttons to the listing. However the linkage is incorrect - the 'more' button should be linking to the actual post and the 'book now' button should be linking externally [click on a post title to see this button in action].

To get these buttons in place I have added the following to the functions.php file


/** Add More button to listing **/
function excerpt_read_more_link($output) {
global $post;
return $output . '<a href="'. get_permalink($post->ID) . '"> <img src="http://www.thehelix.ie/web2011/wp-content/themes/EvolveHelix/image/theme/button_more.png" alt="More"></a>';
}
add_filter('the_excerpt', 'excerpt_read_more_link');

/** Add Book Now button to listing **/
function excerpt_booking_link($output) {
global $post;
return $output . '<a href="'. get_post_meta($post->ID, 'Booking', true) . '"> <img src="http://www.thehelix.ie/web2011/wp-content/themes/EvolveHelix/image/theme/booknow.png" alt="Book Now!"></a>';
}
add_filter('the_excerpt', 'excerpt_booking_link');


I have tried numerous changes, plus the author of the plugin say it is not an issue with their plugin [i think there might be a conflict though]. So basically I'm lost!

Anyone out there know how to fix this?

Thanks
The evolve team

Answers (4)

2011-07-12

Erez S answers:

As far as I see for some reason all the posts have the same wrong address, but there is no bug with the get_permalink() function, so my guess is that the: $post->ID is the ID of the page and not of the post. Try to print the $post->ID and to see what it prints, my guess is that it will print the page ID.


evolve design comments:

Thanks Erez for the reply, excuse my ignorance, but how do I print the $post->ID ?


Erez S comments:

/** Add More button to listing **/

function excerpt_read_more_link($output) {

global $post;

return $output . '<a href="'. get_permalink($post->ID) . '"> <img src="http://www.thehelix.ie/web2011/wp-content/themes/EvolveHelix/image/theme/button_more.png" alt="More"></a>';

}

add_filter('the_excerpt', 'excerpt_read_more_link');



/** Add Book Now button to listing **/

function excerpt_booking_link($output) {

global $post;

return $output . $post->ID . '<a href="'. get_post_meta($post->ID, 'Booking', true) . '"> <img src="http://www.thehelix.ie/web2011/wp-content/themes/EvolveHelix/image/theme/booknow.png" alt="Book Now!"></a>';

}

add_filter('the_excerpt', 'excerpt_booking_link');


Put this code and the ID should be shown near the button.


evolve design comments:

Yes, I placed the code in the excerpt and it returns blank:

function excerpt_read_more_link($output) {
global $post;
return $output . ‘‘;
}
add_filter(‘the_excerpt’, ‘excerpt_read_more_link’);

/** Add Book Now button to listing **/
function excerpt_booking_link($output) {
global $post;
return $output . $post->ID . ‘‘;
}

add_filter(‘the_excerpt’, ‘excerpt_booking_link’);


Erez S comments:

Try this:
function excerpt_booking_link($output) {
global $post;
print_r($post);
return $output . $post->ID . ‘‘;
}
add_filter(‘the_excerpt’, ‘excerpt_booking_link’);


And let me see the result


evolve design comments:

Thanks Erez, the result is on the page:
http://thehelix.ie/web2011/index.php/whatson/


Erez S comments:

You didn't wrote that right, you forgot to write the PHP open tag <?php


Erez S comments:

Anyway also if you can send me the code of the template page and I'll try to fix this

2011-07-12

Denzel Chia answers:

Hi,

Is that a page using a page template? Because it is using the same post id for all your added button permalink.

If it is a template, you should add your button codes within the template's WordPress Loop and not using add_filter in the functions.php

Thanks.
Denzel


evolve design comments:

Hi Denzel, Thanks for the reply. Yes the page is working from a page template.

Do I just place the same code in the loop.php file and remove it from the functions.php.

Sorry not a great php writer.

Thanks
evolve


Denzel Chia comments:

Hi,

You can try adding the below code within your template WordPress Loop,
somewhere near the_excerpt(), the codes are modified from what you posted.

Please remove the codes from your functions.php



global $post;

echo '<a href="'. get_permalink($post->ID) . '"> <img src="http://www.thehelix.ie/web2011/wp-content/themes/EvolveHelix/image/theme/button_more.png" alt="More"></a>';

echo '<a href="'. get_post_meta($post->ID, 'Booking', true) . '"> <img src="http://www.thehelix.ie/web2011/wp-content/themes/EvolveHelix/image/theme/booknow.png" alt="Book Now!"></a>';



If the codes does not work, please post your whole template code here. So that we can see where to add in the codes.
I am answering "blindly" now.

Thanks.
Denzel

2011-07-12

Romel Apuya answers:

Hi,

The link cant be viewed..It redirects to a wp admin login page..


evolve design comments:

Apologies,

The link should now be working:
http://thehelix.ie/web2011/index.php/whatson/

Thanks


Romel Apuya comments:

try using the_permalink() not get_permalink($post->ID);


evolve design comments:

Hi Romel, thanks for the reply, sorry no luck with this, the buttons just disappear


Romel Apuya comments:

how are you pulling these items?
can you post it?


evolve design comments:

They are being pulled in by a plugin called amr events cal:
http://wordpress.org/extend/plugins/amr-ical-events-list/ [http://icalevents.com/]

I have talked to the author of this, but they say that it's an php/html/wordpress filter excerpt issue.

2011-07-12

Christianto answers:

Hi,

The site not viewable without login.. :D
You should use 'excerpt_more'.
the filter should be add_filter('excerpt_more', 'your_function');


evolve design comments:

Sorry Christianto, many thanks for the reply, but no luck with this, the buttons just disappear