Support » Fixing WordPress » Show WordPress on External site with thumbnails

  • I am able to show my latest WP post titles on a .html site with

    /* Short and sweet */
    define('WP_USE_THEMES', false);

    and then

    global $post;
    $args = array( 'posts_per_page' => 3 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a><br />
    <?php endforeach; ?>

    This only shows the titles though.

    How can I get the thumbnail (300px) or an excerpt with Thumbnail showing through?

Viewing 9 replies - 1 through 9 (of 9 total)
  • I’ve tried `<?php
    global $post;
    $args = array( ‘posts_per_page’ => 3 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) : setup_postdata($post); ?>
    <a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?> <?php the_post_thumbnail(); ?></a><br />
    <?php endforeach; ?>`

    But I’m getting a full blown image rather than thumbnail.

    So the issue is that it’s pulling featured image which is not displayed in the post … Hence there’s no thumbnail.

    Anyone know the best resolution for this? eg. how to make featured images have thumbnails?



    very awesome

    Featured imaged do have thumbnails, but not all pages/posts have featured images. If the_post_thumbnail() isn’t showing anything, that means that there’s no featured image set for that post.

    To get around that you need to do a check before you try to output it. As an example…

    <?php if (has_post_thumbnail ()): ?>
        <?php the_post_thumbnail ("thumbnail"); ?>
    <?php else: ?>
        <img src="fallback_image_file.jpg" />
    <?php endif; ?>

    Yes featured images are displaying on the blog along with thumbnails. The issue comes about when having them shown on html with the above code.

    Rather than pulling a thumbnail the above code seems to be pulling the full sized image.

    Are you suggesting to replace

    ?php the_post_thumbnail(); ?>

    With `<?php if (has_post_thumbnail ()): ?>
    <?php the_post_thumbnail (“thumbnail”); ?>`?



    very awesome

    When you read the codex page for the_post_thumbnail() you can see that the first argument for it is the size that you want the image to be, and the default is to supply the image at the thumbnail size, but I’d suggest that you specify that you want ‘thumbnail’. It should work without that, but… I prefer to specify it so I know that it’s going to work as expected.

    If you are not worried about showing a default image if there’s no thumbnail then you don’t have to use the if() statement. I added that there because in your posts before you kept saying that there was no thumbnail for the post, so that was probably me getting confused about what you were really after.

    I tried specifying a size

    <?php the_post_thumbnail( '100' ); ?>

    But it’s still putting the full sized image up.

    So if I upload a 500px image it’s displaying 500 px. Ditto if I upload a 100px. Seems like there’s not thumbnails being made? Which is strange as featured posts do show as thumbnails in excerpts etc.



    very awesome

    Did you try using the word ‘thumbnail’ instead of a number? What I can see wrong is that your exanple uses quotes around the number – which makes it a string and not a numerical value so its treated as the name of a size and not a dimension.

    Yes! that worked!

    <?php the_post_thumbnail(thumbnail); ?>

    Thank you very much for your help. I don’t think I’d ever have tried just using the word “thumbnail” instead of size 🙂



    very awesome

    That’s why it’s always good to read the codes pages for the functions that you’re trying to use. On there is says about the ‘size’ attribute:

    Either a string keyword (thumbnail, medium, large, full), or any custom size keyword defined by add_image_size(), or a 2-item array representing width and height in pixels, e.g. array(32,32).

    So you were doing it wrong, and the default for invalid parameters is to return the image as full size. I’ve found that 99% of the times that I’ve had a function not work correctly it’s been me trying to pass invalid or incorrect values to it.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Show WordPress on External site with thumbnails’ is closed to new replies.