Wordpress PHP Question - Show One Post On Homepage

Discussion in 'PHP' started by phaze3131, Sep 4, 2008.

  1. #1
    I have been searching for how to do this for a few hours and I have just come up empty :(

    I'm wondering if anyone can possibly point me in the right direction of how to accomplish this in wordpress 2.6+.

    Thanks all!

    Travis
     
    phaze3131, Sep 4, 2008 IP
  2. gameOn

    gameOn Member

    Messages:
    624
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    35
    #2
    Is it that you want Only One post from a Particular category appear on homepage or Display a single, latest post from any category on homepage?
    Here is the code to do it >
    
    <?php $recent = new WP_Query("cat=CATEGORY NUMBERshowposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    				<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    				<?php endwhile; ?>
    
    Code (markup):
    Replace CATEGORY NUMBER , with the catgory number from which you want the post to be displayed on home page.

    If you have any doubts regarding this, let me knw
     
    gameOn, Sep 4, 2008 IP
  3. imphpguru

    imphpguru Active Member

    Messages:
    439
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Hi,
    You can control it through the wordpress admin panel. It can be done thourgh settings -> Blog pages show at most (make it 1 instead of 10).

    Thanks
    imphp
     
    imphpguru, Sep 4, 2008 IP
  4. phaze3131

    phaze3131 Well-Known Member

    Messages:
    538
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    140
    #4

    And if I just want it to be the latest post, the most recent post then leave CATEGORY NUMBER blank?


    The default settings where you set it to 1 does not work because then the blog will only display 1 post no matter what the user is trying to do so the user cannot see all posts from say January.


    Thank you again and look forward to your reply :)

    Travis
     
    phaze3131, Sep 4, 2008 IP
  5. Pramudita

    Pramudita Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can't control it through the wordpress admin panel. Setting your blog reading option to 1 can't work, just set to 2 posts/minimum (Blog pages show at most 2 posts not 1)

    Edit your index.php (home page/main index template) and add this (replace default code)

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    Code (markup):
    replace with
    <?php if (have_posts()) : ?>
    <?php
        $recentPosts = new WP_Query();
        $recentPosts->query('showposts=1');
    ?>
    <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
    Code (markup):
    support my blogs if that can solve your problem :D :lol:

    You can see my technology blog as sample. I'll write about this on my blog too

    Thanks
     
    Pramudita, Sep 14, 2008 IP