The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript The Loop. How can I grab most recent post from CATEGORY?

  • This topic is empty.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
  • #33030

    I watched The Loop video twice and took a bunch of notes.

    I can’t even figure out how to pull in a post from a specific category. Based on my notes I took, I thought it would be something like this:

    That code and 5 hours worth of variations of this code gives me nothing but the desire to jump out of a window.

    Can someone please tell me how to grab the TITLE and IMAGE from the MOST RECENT POST in a SPECIFIC CATEGORY?

    Thank you. I hope to receive your instructions before the three days wait is up on a gun purchase with which I plan to blow my brains out.


    The query has to come first. This is from the Snippet section on this very site:


    You’ve made AngryMan pretty happy. Unfortunately, I did figure that out slightly before finding this answer, though much later than you posted it. Oh well, something to be said for self-discovery, I suppose.

    Now, I just need to figure out how to grab THE IMAGE only. Maybe there is a the_image(); function… will work on this tomorrow. Mind needs rest. Thanks again.


    If you used the wonderful featured image function, then you would use:

    If you have put it in the body area of the post/page, you’ll be able to check if the post has any attachments to it and it gets slightly complicated from there. I would definitely use the featured image function!


    AngryMan is going home happy. The kids will not be beaten tonight. Thank you. :)

    PS. I jest about child abuse! HA! I have no kids!

    PPS – Seriously, thank you very much! I was getting so frustrated today. It is good to see that I accomplished something… by finally asking the right person for help!


    Hey no problem! That’s what this forum is for!


    So, I tried this and it’s not showing anything:

    Is there something wrong with this code?
    Do I need an echo or something instead of just

    When I added the image to the post, I clicked the Featured Image link and then the Insert Image button. Is there something else I need to do to make this a Featured Image in order to work?


    I’m starting from Chris Coyier’s “Personal Homepage Theme” from the video tutorial, btw, so it’s possible that if that code looks right and if I added the Featured Image correctly that his theme simply does not support Featured Images. Which seems very possible since I remember he cut a lot of default WP options out of his theme.


    Yeah… crud, that seems to be the case. Anyone know of a better blank theme than Starkers? The way the index.php grabs a loop.php just seems like a convoluted mess to me.


    It’s no problem! Just open up your functions.php and add the thumbnail support. I’m going to post one that I just used in a project:

    // post thumbnail support
    if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );

    if ( function_exists( 'add_image_size' ) ) {
    add_image_size( 'featured-stylist', 220, 220, true );
    add_image_size( 'photo-gallery', 130, 130, true );
    add_image_size( 'stylist-detail', 253, 323, true );
    add_image_size( 'stylist-listing', 150, 150, true );

    You’ll notice that I set up a bunch of different sizes. This is because I don’t want the images to be the same size on different templates.

    In each template I am able to call a specific size by going like this:

    If you add new sizes after an image has already been uploaded, you’ll have to re-upload your images. But wait! There’s a lovely plugin that goes through all of your images and recreates all of the thumbnails for you – phew!

    After you’ve added the thumbnail functionality, you should see a “Set Featured Image” link on the right of your visual editor when editing a post or page in the WordPress backend.


    Oh cool! In the meantime, I had found a simpler version:

    add_theme_support( ‘post-thumbnails’ );
    /*set_post_thumbnail_size( 80, 55, true ); // W x H, hard crop if you want the thumbnails to automatically crop*/

    but yours is way better, obviously!

    Thanks again!

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.