The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

latest post on index page (4 posts)

  1. amaeria
    Posted 6 years ago #

    I wonder how to get the latest post from a specific category /news/ as my index page?
    Title and Photo from the post and when it is clicked i would like to come to all the posts in this category?

    cannot make it work so that the photo shows so now, again, how to do this?

  2. vtxyzzy
    Posted 6 years ago #

    If you are using a freely available theme, post a link to your site and someone may be able to help.

  3. amaeria
    Posted 6 years ago #

  4. vtxyzzy
    Posted 6 years ago #

    Add this function to your functions.php:

    <?php # Displays post image attachment (sizes: thumbnail, medium, full)
    function dp_attachment_image($postid=0, $size='thumbnail', $attributes='',$echo=1) {
       if ($postid<1) $postid = get_the_ID();
       if ($images = get_children(array(
          'post_parent' => $postid,
          'post_type' => 'attachment',
          'numberposts' => 1,
          'post_mime_type' => 'image',)))
          foreach($images as $image) {
             $attachment=wp_get_attachment_image_src($image->ID, $size);
             $img = "<img src='{$attachment[0]}' $attributes />";
             if ($echo) {
               echo $img;
             } else {
               return $img;

    Use this to display your attachment:

    $cat = 39;  // Replace this with your own category id
    if (have_posts()) : while (have_posts()) : the_post();
       $link = get_category_link($cat);
       $echo = 0;
       $img = dp_attachment_image($post->ID,'full','width=90%',$echo);
       if ($img) { ?>
          <h2><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2>
          <a href="<?php echo $link; ?>" > <?php echo $img; ?> </a>
       <?php }

Topic Closed

This topic has been closed to new replies.

About this Topic