• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

Wordpress - Show most recent posts

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
Adam
Asked:
Adam
  • 6
  • 3
1 Solution
 
adeelshahidCommented:
use this,


query_posts('posts_per_page=1');

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

      // show link
      the_permalink();

endwhile;
0
 
AdamAuthor Commented:
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
 
adeelshahidCommented:
buddy try this one,

http://codex.wordpress.org/Function_Reference/query_posts
you will find better idea's to do things here.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
AdamAuthor Commented:
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
 
jeremyjared74Commented:
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
 
adeelshahidCommented:
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
 
AdamAuthor Commented:
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
 
AdamAuthor Commented:
Thanks adeelshahid. I appreciate the help.

I'll give that a try.
0
 
AdamAuthor Commented:
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
 
AdamAuthor Commented:
Please see my last comment for a minor adjustment to the code for it to work properly.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now