Wordpress - Pull just two entries...

Associate
Joined
21 Oct 2008
Posts
1,679
Location
Mooching... in your house
Hi...

What would the best method be for pulling just the two latest entries from something in WP?

basically, its for a news section on a site, and on the home page I just want the two latest posts displayed in a kind of "featured news" section...

how do i limit what is drawn from the category?
 
Code:
$query = "SELECT * FROM blog_posts WHERE post_type='post' AND post_status='publish' ORDER BY post_date DESC LIMIT 2";

You might need to change blog_posts depending on WP version/config
 
ooh christ, didn't realise you'd have to get down and dirty with the SQL :D

thanks for that i'll give it a go :)
 
oh ok... so by XML feed do you mean the "normal" WP way of doing things? maybe something like this?

Code:
<?php $news = new WP_Query("cat=3&showposts=4"); ?>

?
 
no, I mean that wordpress automatically offers an RSS feed, so you could use a PHP function to grab that feed and parse it out as whatever you want.

It depends on what you want to do. If this is a page that has no other WP stuff on it, then personally I think its just easiest to write your own SQL query as above, rather than using the WP classes. If you're wanting to grab the content from one domain/site to another then feeds are best.

For example, we run a wordpress blog:

http://www.engageinteractive.co.uk/blog

On our homepage we bring through the latest headlines, via our own SQL, as the site and wordpress blog are on the same server:

http://www.engageinteractive.co.uk

But in other places we use the XML feed, for example, whenever we build a CMS for a website we also include a feed of our latest blog in the footer so clients can see what we've been up to. In this case the XML feed is better because the sites may be on different servers without db access to each other:

The feed: http://www.engageinteractive.co.uk/blog/feed

The parsed HTML:

http://www.engageinteractive.co.uk/cms/includes/footer.php
 
that is really really cool i'll bear that in mind :)

heres a question:

so you have a section (category) in WP where each post will have content, obviously, but also an associated image that can be displayed on say the home page above the post...

in terms of WP, its perfectly easy to add a custom key with a value of say "custom-image" and call it in the usual way from wherever, however my question is what is the best way to implement this from a clients point of view?

it is not user friendly to ask a client to upload an image of the right size by their own means to a location, and enter the url in the custom field... what would be ideal is a box under the bit where you enter the content with an "upload image" dialogue or something but this doesnt exist... is there a way to do what i want or is it just not possible in WP without writing a custom plugin?
 
Back
Top Bottom