Solved

Wordpress - Show most recent posts

Posted on 2011-03-07
10
399 Views
Last Modified: 2012-05-11
Hi there!

I am building a custom Wordpress theme and need to show the most recent posts on the homepage. However, I want to show the latest post as a "Featured Article" where it will show the title, an excerpt, and a link to the full post. For the following posts, I only want to show the title and a link to the article.

I know how to show the most recent posts using "query_post", but I'm not entirely sure how to pull this off. Would someone be able give me a hand? Thanks.
0
Comment
Question by:Adam
  • 6
  • 3
10 Comments
 
LVL 2

Expert Comment

by:adeelshahid
ID: 35057172
use this,


query_posts('posts_per_page=1');

while ( have_posts() ) : the_post();
      
      // show title
      the_title();

      // show link
      the_permalink();

endwhile;
0
 
LVL 1

Author Comment

by:Adam
ID: 35057539
Thanks adeelshahid.

However, unless I'm mistaken, won't your solution just show the title and link for a single post? I think you might have misread my question.

I was asking for a way to show the most recent post (title, link, and an excerpt from the article) then, all the following articles, i want to show just the title and link.

I appreciate the help but I think your solution only covers part of what I'm looking to do. Do you know what I would need to do to achieve what I'm looking for?

0
 
LVL 2

Expert Comment

by:adeelshahid
ID: 35057561
buddy try this one,

http://codex.wordpress.org/Function_Reference/query_posts
you will find better idea's to do things here.
0
 
LVL 1

Author Comment

by:Adam
ID: 35057639
Thanks - I've looked through the reference before.

I have a specific question that I was looking to get help with which is why I posted here.
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 35057697
To get the latest posts in a list format add this to the loop:
<?php get_archives('postbypost', '10', 'custom', '<li>', '</li>'); ?>

Open in new window

This will show the 10 latest posts in a list.


Recent Posts with Summary:
    <ul>
    <?php query_posts('showposts=5'); ?>

    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>

    <li><?php the_excerpt(__('(more…)')); ?></li>
    <?php endwhile;?>
    </ul>

Open in new window


Recent Posts with Full Content
    <ul>
    <?php query_posts('showposts=5'); ?>

    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>

    <li><?php the_content(__('(more…)')); ?></li>
    <?php endwhile;?>
    </ul>

Open in new window


Let me know if you nave any questions.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 2

Accepted Solution

by:
adeelshahid earned 500 total points
ID: 35057796
query_posts('posts_per_page=1');

$post_id = -1;

while ( have_posts() ) : the_post();
     
        $post_id = $post->ID;
        
      // show title
      the_title();

      // show link
      the_permalink();
        
        // show content
      the_content('...continue');

endwhile;

query_posts(
                  array(
                          'posts_per_page' => 10,
                          'post__not_in' => $post_id,
                          'post_status' => 'publish'
                          )
                  );

$counter = 1;
while (have_posts()) : the_post();
      
      the_title();
      the_permalink();
      the_content('...continue');

endwhile;
0
 
LVL 1

Author Comment

by:Adam
ID: 35057849
Hi Jeremy,

Thanks for the reply. But I think something might still be missing here. To make this more simple, this is what I'm looking to show on the homepage:

Post Title 1
>>Article Text
Read More Link

Post Title 2
Read More Link

Post Title 3
Read More Link

So from the sounds of it, I need two query posts. One that shows the latest post with text, the a second that shows the other recent posts (without the latest post - as it will already be showing) and doesn't show the article text.

Does that make sense?
0
 
LVL 1

Author Comment

by:Adam
ID: 35057904
Thanks adeelshahid. I appreciate the help.

I'll give that a try.
0
 
LVL 1

Author Comment

by:Adam
ID: 35058204
adeelshahid:

I gave the code you provided a try and initially got an error. It was stemming from 'post__not_in'. I did a little searching a found a forum where someone mentioned that 'post__not_in' needs to call an array. So I changed:
post__not_in' => $post_id

Open in new window

to
post__not_in' => array($post_id)

Open in new window

And it seems to be working just fine now. Thanks so much for the help!
0
 
LVL 1

Author Closing Comment

by:Adam
ID: 35058243
Please see my last comment for a minor adjustment to the code for it to work properly.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now