• musk

    (@musk)


    I am trying to create a static page with 3 things; some text, the 5 latest posts of my blog w/ time and date, and 5 latest updated galleries.

    I’ve read the WordPress tutorial on creating static pages and I’m using the code it gives me (listed below). And it works fine if you just want the title. But I would like to have the time of the post either next to the title or underneath the title. I keep trying to use “get_time” and it just won’t work. Any suggestions?

    Example of the site: here


    <?php
    $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
    ID,post_title FROM $wpdb->posts
    WHERE
    post_status= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
    foreach($news as $np){
    print ("<li><a href=\"");
    echo get_permalink($np->ID);
    print ("\">$np->post_title</a></li>");
    } ?>
    </ol>

Viewing 6 replies - 1 through 6 (of 6 total)
  • Kafkaesqui

    (@kafkaesqui)

    Try this for your print()/echo lines:

    print ("<li><a href=\"");
    echo get_permalink($np->ID);
    print ("\">$np->post_title</a> (");
    echo mysql2date(get_settings('date_format'), $np->post_date);
    print (")</li>");

    Note how I call the default date format from your blog through get_settings() (which is filtered through mysql2date()), but you can replace this with a custom date format string.

    EDIT: Altered code to match your swap out of printf().

    Thread Starter musk

    (@musk)

    Nope, still doesn’t work. The new code I have in there is (again, example here:


    <?php
    $how_many=5; //How many posts do you want to show
    require_once("./blog/wp-config.php"); // Change this for your path to wp-config.php file ?>
    <ol id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT
    ID,post_title FROM $wpdb->posts
    WHERE
    post_status= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
    foreach($news as $np){
    print ("<li><a href=\"");
    echo get_permalink($np->ID);
    print ("\">$np->post_title</a> (");
    echo mysql2date(get_settings('date_format'), $np->post_date);
    print (")</li>");
    } ?>
    </ol>

    Kafkaesqui

    (@kafkaesqui)

    Try including wp-blog-header.php instead:

    require_once("./blog/wp-blog-header.php");

    Thread Starter musk

    (@musk)

    I already have that in the file. here, let me post the entire code:


    <?php
    /* Short and sweet */
    define('WP_USE_THEMES', false);
    require_once('./blog/wp-blog-header.php'); get_header();
    ?>

    <div id="content" class="narrowcolumn">
    <div class="alt">

    <?php
    $how_many=5; //How many posts do you want to show
    require_once("./blog/wp-config.php"); // Change this for your path to wp-config.php file ?>
    <ol id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts
    WHERE
    post_status= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
    foreach($news as $np){
    print ("<li><a href=\"");
    echo get_permalink($np->ID);
    print ("\">$np->post_title</a> (");
    echo mysql2date(get_settings('date_format'), $np->post_date);
    print (")</li>");
    } ?>
    </ol>

    </div>
    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

    Kafkaesqui

    (@kafkaesqui)

    Sorry I missed this first time around, but the problem is you’re not collecting the post_date record in your query:

    $news=$wpdb->get_results("SELECT ID,post_title,post_date FROM $wpdb->posts
    WHERE post_status= "publish" ORDER BY 'ID' DESC LIMIT ".$how_many);

    Thread Starter musk

    (@musk)

    ok, i finally got the date and time to show up. how can I format it so it shows up the way i want to?

    btw, thanks for all this help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Static Page Help’ is closed to new replies.