• Dear, I use WP 2.5.1.
    I’m reading (on the codex section) how to create Static Page with Mini-Loop. I found this code:

    <?php
      define('WP_USE_THEMES', false);
      require('./wp-blog-header.php');
      get_header();
    ?>
    <div id="content" class="narrowcolumn">
    <h1>Welcome to my site</h1>
    <p>Hello and welcome to my site. You can go to my web page about how to improve your
    shoots with your digital camera; or you can go to my blog</p>
    
    <h2>Latest posts in my blog:</h2>
    
    <?php
      # Here starts Mini Loop trick: You can use this code, but _at your own risk_
      # If you want to improve this code, you're welcome ;)
      $how_many=7; //How many posts do you want to show
    ?>
    <ul class="whats-new">
    <?php
      $news=$wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts
        WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>= \"publish\" ORDER BY <code>post_date</code> DESC LIMIT $how_many");
      foreach($news as $np){
        printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);
      }
    ?>
    
    </ul></div>
    <?php
      get_sidebar();
      get_footer();
    ?>

    I would like to set just a category to be seen. How can I do this?
    I think I’d have to add something like ‘cat_ID’=NUMBER in the WHERE condition. I’ve tried but it doesn’t work.

    Any suggestion?

    Many thanks

The topic ‘Trasforming this code’ is closed to new replies.