Solved

Wordpress - Show most recent posts

Posted on 2011-03-07
10
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

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
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

728 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