• Hello
    How to get a thumbnail of the latest post on my main page?
    i have tried with :

    <?php query_posts(‘cat=6&posts_per_page=1&orderby=rand’); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class=”postthumb1″>
    <?php post_thumb(); ?>
    <p class=”undertheimage”><b>NEWS</b></p>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>

    But this only takes me to the whole menue of ALL the posts in this category and i want to be taken to the latest post simply…………?

    how to do???

Viewing 7 replies - 1 through 7 (of 7 total)
  • <?php
    $args=array(
      'cat' => 6,
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        $attachments = get_posts( array(
        'post_type' => 'attachment',
         'number_posts' => 1,
        'post_status' => null,
        'post_parent' => $my_query->post->ID,
        'orderby' => 'post_date',
        'order' => 'DESC',
        ) );
        if ($attachments) {
          $thumbnail_id = $attachments[0]->ID;
          echo wp_get_attachment_image( $thumbnail_id );
        }
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    Thread Starter amaeria

    (@amaeria)

    doesnt work…
    i tried adding it in index but nothing happened…..
    ?

    Please paste all the code from the theme template file (including the code that you used from the example above) into a pastebin such as wordpress.pastebin.com, and report the link back here. Maybe someone can spot your problem. Thanks..

    Thread Starter amaeria

    (@amaeria)

    Thread Starter amaeria

    (@amaeria)

    seems i can get the text from the post but not the thumbnail or the image itself….?

    and when i clock the text it all jumps left but i guess this has to do with the css of course and that i have to change something there to centre all….

    however, still no image…

    Looks okay to me and it works for me…
    after ‘if ($attachment)` you might put this to see what it is returning:

    echo "<pre>"; print_r($attachments); echo "</pre>";
    Thread Starter amaeria

    (@amaeria)

    Hey again, still cant make it work…
    so again.

    what i want is simply to get the latest posts in one category “NEWS” as the index page….
    how to do this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘thumbnail of latest post on main page….’ is closed to new replies.