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
Display most recent post in Wordpress
Old 11-30-2009, 03:40 PM Display most recent post in Wordpress
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
After a couple of months of not touching my new portfolio website design I've finally got around to continuing it.

I keep struggling getting Wordpress to do the simplest of tasks though! Here I'm simply trying to get it to display my most recent post on the homepage... it was working originally but I must have altered something without realising and now it's just displaying all of them!

Here is the code I have in my index.php (it's using example code from the Codex)

PHP Code:
        <?php $my_query = new WP_Query('posts_per_page=1');
          while (
$my_query->have_posts()) : $my_query->the_post();
          
$do_not_duplicate $post->ID;?>
                        <div id="h1-wrapper"><h1><?php the_title(); ?></h1></div>
                            <div class="detail">
                              <span class="info">Filed under <?php the_category(', ''multiple'); ?> | <?php the_date(); ?></span>
                              <span class="listening-to">Listening to: <span class="highlight">Orbital</span></span>
                            </div>
                            <div class="content">
                                <?php the_content(); ?>
                            </div>
          <?php endwhile; ?>
            
          <?php if (have_posts()) : while (have_posts()) : the_post(); 
          if( 
$post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
                        <div id="h1-wrapper"><h1><?php the_title(); ?></h1></div>
                            <div class="detail">
                              <span class="info">Filed under <?php the_category(', ''multiple'); ?> | <?php the_date(); ?></span>
                              <span class="listening-to">Listening to: <span class="highlight">Orbital</span></span>
                            </div>
                            <div class="content">
                                <?php the_content(); ?>
                            </div>
          <?php endwhile; endif; ?>
Can anybody see the problem?

Oh and I thought I would post the problem here, as I find the official Wordpress forum is useless! Anybody else find that?
__________________

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 12-02-2009, 07:35 AM Re: Display most recent post in Wordpress
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Never Mind,
I managed to get it working in the end using this

PHP Code:
query_posts('posts_per_page=1');
if ( 
have_posts() ) : while ( have_posts() ) : the_post();
    
entry();
endwhile;
endif; 
Far simpler than the original method (not sure why I used that!)
__________________

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 Display 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.10355 seconds with 12 queries