• Hello all,

    I am trying to display the most recent post of my Events category on my home page. So far it’s going well, everything is displayed as intended (date, title and content). This is my code:

    <?php $recent_events = new WP_Query(); ?>
    <?php $recent_events->query('cat=4&showposts=1'); ?>
    <?php global $more; ?>
    <?php while($recent_events->have_posts()) : $recent_events->the_post(); ?>
            <li id="events-news">
                <p><?php the_date('d/m Y'); ?></p>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                <?php $more = 0; the_content("More..."); ?>
           </li>
    <?php endwhile; ?>

    Now: I would like to display images as well, which it does at the moment, but my question is, how do I resize the post images to display as (max-width: 50px / max-height:50px) thumbnails?

    Thanks in advance!

    em

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kjeft

    (@kjeft)

    Oh and one more thing, is there a way of making the title link (<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>) to link to the category page rather than the permalink to the post?

    So if someone clicks on the title it brings them to my Events News page, and if they click on the ‘More…’ it takes them to the single post (as it does at the moment).

    Cheers!

    You might try this for thumbnail images:

    Add this code inside your “while” loop.

    <?php if( get_post_meta($post->ID, "thumbnail", true) ): ?><a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;" src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="<?php the_title(); ?>" /></a><?php else: ?><?php endif; ?>

    Now, you must add the “thumbnail” meta data for each new post.

    1. Go to create a New Post.
    2. Near the bottom of the page, Add Custom Field called “thumbnail”.
    3. The value for the Custom Field is the URL of your thumbnail image.

    I hope this helps

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Resize post image to thumbnail size’ is closed to new replies.