WordPress.org

Forums

Show external images in post within thumbnail (10 posts)

  1. Nirok
    Member
    Posted 5 years ago #

    Hi i'm using WP 2.8.6 . I don't know how to put this into a search and i have done quite a few different search terms but with nothing that can help me, so thought i'd post this here.

    My issue is that I sometimes use external images within posts and I have several wordpress installs linked together (different databases), so that when a new post is added to one it gets sent and displayed on another. Hence this creates external image links. On my homepage I have it so different categories display there latest posts. This shows the post title, a small number of words and also the first picture from the posts gallery. Now this is all great and looks amazing. However it won't display the external images of a post which only uses external images.... can anyone point me in a possible direction of maybe a plugin or a call function that may call the first image of any post? i.e. grab the "img" source? I can see call functions with regards to attachments and galleries just not to sure how you would go about creating something which grabs the first image of a post. I would replace the current call function which only grabs the first image of the gallery with this new call function grabbing the first image of a post....

    Any help would be much appreciated

    Thanks

  2. alchymyth
    Forum Moderator
    Posted 5 years ago #

  3. Nirok
    Member
    Posted 5 years ago #

    Hey thanks this is another way of doing it! I actually just did this:
    Added this to functions.php

    function getImage($num) {
    global $more;
    $more = 1;
    $link = get_permalink();
    $content = get_the_content();
    $count = substr_count($content, '<img');
    $start = 0;
    for($i=1;$i<=$count;$i++) {
    $imgBeg = strpos($content, '<img', $start);
    $post = substr($content, $imgBeg);
    $imgEnd = strpos($post, '>');
    $postOutput = substr($post, 0, $imgEnd+1);
    $postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);;
    $image[$i] = $postOutput;
    $start=$imgEnd+1;
    }
    if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'">'.$image[$num]."</a>"; }
    $more = 0;
    }

    and then added this to the template:
    <?php getImage('1'); ?>

  4. Nirok
    Member
    Posted 5 years ago #

    Its great to see there so many different ways, i'll check out this way and see if its better than the above solution... i'm gonna definitly use that link plugin to resize it aswell

    Awsome I love WordPress!!

  5. Mixtaka
    Member
    Posted 5 years ago #

    Hello Nirok

    Can you tell me where exactly i have to paste the code in functions.php, i try this but i did not success i have a same problem, my theme did not support external images, this is my site - http://www.movieflake.com/

    please also tell exactly where to add this code <?php getImage('1'); ?>
    in template.

    i really very thankful to you

    Thanks

  6. Mixtaka
    Member
    Posted 5 years ago #

    Hi nirok

    this is my function file please tell me where i add the code

    [Code moderated as per the Forum Rules. Please use the pastebin]

    please also tell exactly where to add this code <?php getImage('1'); ?>
    in template.

  7. Mixtaka
    Member
    Posted 5 years ago #

    Hi nirok

    this is my function file please tell me where i add the code

    http://wordpress.pastebin.ca/1829563

    please also tell exactly where to add this code

    <?php getImage('1'); ?>

    in template.

    im waiting for your reply

  8. Mixtaka
    Member
    Posted 5 years ago #

    Hello Nirok

    now i add the script successfully and it work, but still facing one problem, how to resize the image as i want. now the image show there original width and height

    Thanks

  9. mxv
    Member
    Posted 4 years ago #

    Can someone tell me where to what template I need to put that last nite of php in?

    I added the big chunk of code to my functions.php for the theme already.

    I'm trying to get thumbnails to show up in my category pages for posts that have images from an external server (ie: amazon or flickr)

    Thanks.

    The site in question if someone can help:

    http://www.punkvinyl.com/category/reviews

  10. gopacific
    Member
    Posted 4 years ago #

    Hello Nirok

    It's good.
    But, how can change image size ?. It seems to ocall original size image.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic