Home › Forums › JavaScript › The Loop. How can I grab most recent post from CATEGORY?
- This topic is empty.
-
AuthorPosts
-
June 7, 2011 at 4:47 pm #33030
AngryMan
ParticipantI 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.
June 7, 2011 at 5:06 pm #73962TheDoc
MemberThe query has to come first. This is from the Snippet section on this very site:
June 7, 2011 at 6:31 pm #73963AngryMan
ParticipantYou’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.
June 7, 2011 at 7:42 pm #73972TheDoc
MemberIf 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!
June 7, 2011 at 7:56 pm #73976AngryMan
ParticipantAngryMan 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!
June 8, 2011 at 1:06 am #73926TheDoc
MemberHey no problem! That’s what this forum is for!
June 8, 2011 at 11:31 am #73867AngryMan
ParticipantSo, 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?
June 8, 2011 at 11:41 am #73854AngryMan
ParticipantI’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.
June 8, 2011 at 11:44 am #73855AngryMan
ParticipantYeah… 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.
June 8, 2011 at 12:12 pm #73838TheDoc
MemberIt’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.
June 8, 2011 at 3:00 pm #73765AngryMan
ParticipantOh 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!
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.