• Resolved holyyakker

    (@holyyakker)


    I am looking to create a mini-loop as part of a mostly Static page. However, for the purposes of CMS I want the rest of the page (mostly a welcome message) to be something that can be edited by another user.

    If I were to create a page called “Welcome Message” and in the page.php Template added this code:

    <?php
    if(is_page('Welcome Message'))
    {
    $how_many=5; //How many posts do you want to show
    require_once('wp-config.php'); // Change this for your path to wp-config.php file ?>
    
    <ol id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);
    }
    }?>

    Do you think that would do what I wanted?

Viewing 2 replies - 1 through 2 (of 2 total)
  • MichaelH

    (@michaelh)

    Might be easier to use this plugin:
    https://aralbalkan.com/1016

    Also, a recent posts plugin such as https://www.ads-software.com/extend/plugins/recent-posts-plugin/ will do this.

    Otherwise, this code in a Page Template could work:

    <?php
    $posts=get_posts('post_type=post&showposts=3');
    if ($posts) {
    foreach($posts as $post) {
    setup_postdata($post);
    ?>
    <p><?php the_time('m.d.y') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php }
    }
    ?>

    Thread Starter holyyakker

    (@holyyakker)

    For the record the code I tried did work – however I’m going to see if the plugins and see if they allow me greater flexibility.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Including a Miniloop using Template Tags’ is closed to new replies.