Adding Custom Fields To Excerpts
AnonymousAugust 25, 2011 at 5:13 pm #1620
I have two custom fields for posts which I would like to be able to include in the post excerpts – one is for a price & the other is for the a link to an image to be used. I need to use an image url as opposed to the post thumbnail as I don’t actually have all the images hosted on my site (as data is populated from an affiliate feed) and so need to link to the image via the url instead.
I have seen examples online showing how to add custom fields to the php files but I have not been able to get them to display on my site.
e.g. I have tried adding the following code to loop.php in <div class=”excerpt-thumb”> replacing the current thumbnail code but have not got it working yet.
<?php if ( get_post_meta($post->ID, 'Img-url', true) ) : ?>
<img />ID, 'Img-url', true) ?>" alt="<?php the_title(); ?>" />
<?php endif; ?>
It may be I am adding the code in completely the wrong place or missing something out so would be grateful if any one has any suggestions of the best way of achieving this.
Thanks for your reply – I actually managed to resolve this in the end but hadn’t had a chance to add to this post yet.
I think I must have either deleted a bit more than I needed too or not enough when I tried adding the above code into the loop file.
I had to create a child theme to help solve something else and so ended up adding child loop files e.g. loop-category.php to override the standard loop for the relevant pages.
Just out of interest how would this be achieved in the Grpahene post-specific options as I couldn’t see anything in there allowing images or custom fields to be displayed in an excerpt.
You must be logged in to reply to this topic.