Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Website Design Forum


You are currently viewing our Website Design Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Targeting the most recent post in Wordpress
Old 09-18-2009, 08:09 AM Targeting the most recent post in Wordpress
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
I have a list of excerpts on my homepage, but I want to target the most recent post and display it in a different way.


I was hoping to do it without the use of a plugin but there doesn't appear to be any conditional tags for it to be possible.


Will I need to use a plugin for it or could I simply add something to functions.php?
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 09-18-2009, 04:26 PM Re: Targeting the most recent post in Wordpress
Skilled Talker

Posts: 64
Trades: 0
http://en.forums.wordpress.com/
wachtn is offline
Reply With Quote
View Public Profile
 
Old 09-18-2009, 04:47 PM Re: Targeting the most recent post in Wordpress
Leopard's Avatar
Extreme Talker

Posts: 242
Trades: 0
Code:
<?php query_posts('showposts=5'); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile;?>
</ul>

Last edited by Leopard; 09-18-2009 at 04:49 PM..
Leopard is offline
Reply With Quote
View Public Profile
 
Old 09-23-2009, 09:24 AM Re: Targeting the most recent post in Wordpress
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
How do you mean target the first post in a different way?
Do you mean show a longer preview than the excerpt?
Show it somewhere else on the page?

You will most likely want to create two separate loops. The first querying 1 post, the second querying the normal posts but excluding the first. Similar to:
<?php query_posts('showposts=5&offset=1');?>

http://codex.wordpress.org/The_Loop
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Old 09-23-2009, 02:10 PM Re: Targeting the most recent post in Wordpress
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Thanks for the tips. I've currently got my homepage so that it displays the whole content of the first post, and then excerpts of those that follow, using the following code:

PHP Code:
        <?php if(have_posts()) : ?><?php $first_post = ( $paged == ) ? $posts[0]->ID ''?>
            <?php while(have_posts()) : the_post(); ?>
                <?php if ($first_post == $post->ID) : ?>
                    <div class="entry">
                        <div id="h1-wrapper">
                          <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <span class="date"><?php the_date(); ?></span></h1>
                        </div>
                        <div class="detail">Filed under <?php the_category(', '); ?>, posted by <a href="#">Matt</a></div>
                        <div class="content">
                            <?php the_content(); ?>
                        </div>
                    </div>
                <?php endif; ?>
                <?php if ($first_post != $post->ID) : ?>
                    <div class="entry">
                        <div class="h2-wrapper">
                          <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <span class="date"><?php the_date(); ?></span></h2>
                        </div>
                        <div class="detail">Filed under <?php the_category(', '); ?>, posted by <a href="#">Matt</a></div>
                        <div class="content">
                            <?php the_excerpt(); ?>
                        </div>
                    </div>
                <?php endif; ?>        
            <?php endwhile; ?>
        <?php endif; ?>
Would it be better to achieve this using query_posts() ? Also, does anyone know how I could show say, 300 characters of the first post instead of all of it, then for the remaining posts to be excerpts of the default length?
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Reply     « Reply to Targeting the most recent post in Wordpress
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43309 seconds with 12 queries