Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Blogging Forum


You are currently viewing our Blogging Forum as a guest. Please register to participate.
Login



Reply
Get Most Recent Post - Wordpress
Old 04-26-2010, 04:10 PM Get Most Recent Post - Wordpress
MattGoucher's Avatar
Skilled Talker

Posts: 64
Name: Matt
Location: California
Trades: 0
Hey Webmasters,

I recently stumbled upon a small issue. My goal was to install wordpress and use it as a CMS. Now I want to query the latest post and echo it out on my homepage. Is there a WP function to do this? Because I noticed that the way that WP stores the posts in the database is very different.

Ideas?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Invalid Code On A New Website Is Like Having A New Car With A Broken Windshield
MattGoucher is offline
Reply With Quote
View Public Profile Visit MattGoucher's homepage!
 
 
Register now for full access!
Old 04-26-2010, 08:09 PM Re: Get Most Recent Post - Wordpress
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
If your home page is the same as your main blog page then you can set this up through WordPress admin setting. Choose to show only one post and choose to show the full post.

If your home page isn't not your main blog page, but is a WordPress page you can do something like this.

PHP Code:
<?php $recent = new WP_Query("showposts=1");
while(
$recent->have_posts()) : $recent->the_post();?>
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
<?php the_content() ?>
<?php 
endwhile; ?>
That will give you the title (linked to the single post) and the content of the post. The key is setting a new WP_Query and then using that new query in the loop.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 04-27-2010, 09:51 AM Re: Get Most Recent Post - Wordpress
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
Quote:
Choose to show only one post and choose to show the full post.
I was thinking the same thing at first but then I realized that if a user wanted to go through the archives they'd have to view one post per page as well. I think you'd be better off using query_posts(posts_per_page=1) right before the loop. (Or if it is the index page then a conditional check if is_home(), etc.)

Also, where do you set "show the full post" in the admin area? I have never seen that?

This question actually sparked my interest when I realized the original goal might have been how to display a full post as the home page WITH the comments and comment form as well(just as if it were a post). That is something I have not done yet with a wordpress custom theme and it is a little weird imo that you can't choose a post directly from the admin area for a home page.

After a little research I saw that just before the loop you can add:
PHP Code:
<?php 
query_posts
('posts_per_page=1');
$wp_query->is_single true
// then start loop here as normal
?>
The $wp_query->is_single = true treats the page like a post and shows the FULL post instead of the intro.
The only other thing is that you'd have to add the comment call comments_template() if the home page template didn't have it.

Just thought I'd pass this along.

Last edited by racer x; 04-27-2010 at 09:53 AM..
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Old 05-02-2010, 05:33 PM Re: Get Most Recent Post - Wordpress
Novice Talker

Posts: 12
Name: Alejandro
Trades: 0
Use this plugin http://wordpress.org/extend/plugins/...osts-per-page/

This will allow you to easily manage the number of posts in your homepage without affecting the archives and search results.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

alexwebseo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Get Most Recent Post - Wordpress
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20850 seconds with 12 queries