SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Show 3 latest posts in WP

    Hey,

    I am trying to show the 3 latest posts on my homepage, and have tried with this code:-

    PHP Code:
             <?php
            
    require('blog/wp-blog-header.php');

               while (
    have_posts()) : the_post('showposts=3'); ?>
               
             <strong id="post-<?php the_ID(); ?>">
             <a href="<?php the_permalink() ?>" style="color:#fff" rel="bookmark" title="Permalink to <?php the_title_attribute(); ?>">
             <?php the_title(); ?></a></strong>
             <br/>
           <small><?php the_time('j F Y'?></small>
           <br/>
            <?php endwhile; ?>
    But it does not seem to work, it shows all of the posts. can anybody help me fix this problem..?

    Regards

  2. #2
    Word Painter silver trophy Shyflower's Avatar
    Join Date
    Oct 2003
    Location
    Winona, MN USA
    Posts
    10,053
    Mentioned
    142 Post(s)
    Tagged
    2 Thread(s)
    Is there a reason why you aren't doing that in the "Reading" settings in your dashboard?

    If not, I would take out your code and go to those settings and set them to display three posts. Then the latest three posts will show on your front page.
    Linda Jenkinson
    "Say what you mean. Mean what you say. But don't say it mean." ~Unknown

  3. #3
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont understand what you mean when you say "Reading" settings in "Dashboard"?

    Basically i am displaying the 3 latest posts on my homepage as it is not wordpress, so i require the pages i need in order to do this. This works, but i thought there would be codex to display the 3 latest posts, but the code i have does not appear to work

  4. #4
    Word Painter silver trophy Shyflower's Avatar
    Join Date
    Oct 2003
    Location
    Winona, MN USA
    Posts
    10,053
    Mentioned
    142 Post(s)
    Tagged
    2 Thread(s)
    Okay, so your homepage isn't a blog page then and/or isn't attached to your WordPress Blog?

    I don't know how you can access your blog database to put it on a static page outside the WP loop. I think your best bet is to put a feed on your home page. A free application to do that is feed informer.
    Linda Jenkinson
    "Say what you mean. Mean what you say. But don't say it mean." ~Unknown

  5. #5
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I already have the posts reading out of the WP database though..

    See this link:-

    http://www.meyselections.com/

    You can see the posts from the blog towards the middle of the page. The reason why i have included the required files etc is because my homepage is NOT wordpress.

    I have managed to pull out the posts but dont exactly knwo the codex to restrict it to show 3 posts..

  6. #6
    Word Painter silver trophy Shyflower's Avatar
    Join Date
    Oct 2003
    Location
    Winona, MN USA
    Posts
    10,053
    Mentioned
    142 Post(s)
    Tagged
    2 Thread(s)
    I am quite clueless when it comes to php. However, I think in order to do what you want to do, you will need to query your WP database from your home page. So I will move this thread to php so you can maybe get the help you need.
    Linda Jenkinson
    "Say what you mean. Mean what you say. But don't say it mean." ~Unknown

  7. #7
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I have not idea how wordpress works, but using regular php you can do the following...
    PHP Code:
             <?php

            
    require('blog/wp-blog-header.php');


                
    $iNumberOfPosts 0;
               while (
    $iNumberOfPosts && have_posts()) : the_post('showposts=3'); ?>

               

             <strong id="post-<?php the_ID(); ?>">

             <a href="<?php the_permalink() ?>" style="color:#fff" rel="bookmark" title="Permalink to <?php the_title_attribute(); ?>">

             <?php the_title(); ?></a></strong>

             <br/>

           <small><?php the_time('j F Y'?></small>

           <br/>
            <?php $iNumberOfPosts++; ?>
            <?php endwhile; ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2009
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nothing on your site looks like you are using wordpress, or cant i see where you are using WP??

    what pages ...?

  9. #9
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    I have fixed the problem, thanks SilverBulletUK your code worked.

    Regards


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •