Solved

Wordpress - Show most recent posts

Posted on 2011-03-07
10
395 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Read about why website design really matters in today's demanding market.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The purpose of this video is to demonstrate how to Import and export files in WordPress. 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 : Click on Too…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

12 Experts available now in Live!

Get 1:1 Help Now