Extension of the excerpt field (3 posts)

  1. Odolyte
    Posted 5 years ago #


    I make templates for clients.

    Quite often i have that request that doesn't have a simple solution :
    - my clients want list of articles with images + text different from the core of the article like :

    Title 1
    Image1 + teasing text for article 1 + read More

    Title 2
    Image2 + teasing text for article 2 + read More

    When they click on the "read more" link they want the article but with different text than the teasing and a different image than the one in the list.

    So my problem is :
    - the "read more" tag is not the solution as images+text in the list will be find in the detail
    - excerpt is just text so no images possible.

    My solution for the moment is to use excerpt + 1 custom field for the URL of the image. But it's not a clean solution (and this means you have the url of the image you want to use with the correct size!!).

    I don't understand why this has never been implemented. For instance, you may want to have different size of images in the list of articles and in the article (small or square images in the list, but big and large in the article or simply different images).

    Could it be possible to extend the excerpt field to accept images (with a button to load the image in the field) or a seperate field close to the excerpt that allows a different image than the one in top of an article ?

    Thanks for reading this crazy wish !!


  2. Tara
    Volunteer Moderator
    Posted 5 years ago #

  3. junixblog
    Posted 5 years ago #

    for the Image this is the script, paste this into your functions.php file:

    function bm_extract_string($start, $end, $original) {
    $original = stristr($original, $start);
    $trimmed = stristr($original, $end);
    return substr($original, strlen($start), -strlen($trimmed));

    add this inside the while loop, this will create a variable that is assigned of the link of the first image attached in your post:

    $content = get_the_content();
    $pic_string = bm_extract_string('src="','" ',$content);

    and then to print it into an img tag:

    <img src="<?php echo $pic_string; ?>" />

    Disclaimer: I do not own the code, I just found it by browsing into google and I can't seem to find the link again, so posted it anyway for everyone. If your the owner or you know the owner of this code, please let me know.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.