• Hey
    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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • If you are using a freely available theme, post a link to your site and someone may be able to help.

    Thread Starter amaeria

    (@amaeria)

    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:

    <?php
    $cat = 39;  // Replace this with your own category id
    query_posts("posts_per_page=1&caller_get_posts=1&cat=$cat");
    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 }
     endwhile;
    endif;
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘latest post on index page’ is closed to new replies.