Solved

Wordpress - Show most recent posts

Posted on 2011-03-07
10
404 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

735 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