Support » Developing with WordPress » Display posts from TODAY

  • Ignacio


    I´ve been using wordpress for an online newspaper.

    I´m using K2 for the theme. Since it´s a newspaper, i only want to show todays posts on the index page. I had no luck on k2 forums. i was hoping someone here can help me.

    thanks a lot in advance!

Viewing 9 replies - 1 through 9 (of 9 total)

    That retrieves the *latest day* in which one or more posts occur. It’s likely you don’t want an empty front page until a post for the present day appears. You would put the example code in your template(s) before The Loop, to initialize it.



    thanks a lot!

    i´ll try this right now!

    can´t believe i missed that in my searches



    Nope, just didn´t work. It displayed a number only. Maybe k2 functions are messing with that. Looks like i have no luck on this matter 🙁


    Let me set up K2 on my local installation and I’ll report back on what you may need to do (if, you know, I find something different).

    Ok, possible solution for K2. First, you need to edit K2’s theloop.php template. In there, locate this section:

    	/* Check if there are posts */
    	if ( have_posts() ) {

    You want to modify this php tag by slipping in the following just after <?php but before the /* Check if there are posts */ line:

    if ( is_home() && !$_SERVER['QUERY_STRING'] ) {
    	$latest = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC LIMIT 1");
    	$latest = str_replace('-', '', substr($latest, 0, 10));
    	query_posts('m=' . $latest . '&showposts=-1');
    	$wp_query->is_archive = false; $wp_query->is_home = true;

    EDIT: Stuck in the $_SERVER[] portion of the if test to deal with that steekin’ archive link/scrollbar. Not perfect though (‘older’ posts rely on standard query/posts_per_page, so it can be off from the home page).



    i´m about to try that solution
    i´ve been strugling with the loop to find the query on the index and as a result, now i´m nuts 😀

    i also got rid of the rolling archives, i don´t need to show posts from older days anymore. so your solution seems perfect for this case!!!

    let me try and come again, but thanks A LOT in advance!



    it worked like a charm!!!
    aahhhhhhhhh what a relief

    there´s only one more thing i´d like to do but it will sound like throwing a bomb here. i apologize in advance for such a php newbie question…

    now i finally have the index showing all posts from today using your code. and then there comes the loop itself to style and show each post.
    can i make it so:

    first 3 news
    <?php this style (the complete theloop.php one) ?>

    next 10 o 15
    <?php this style (less stuff than the other) ?>

    all others
    <?php this style (title only) ?>

    maybe it´s some code after
    if ( have_posts() ) {

    Simplest method for accomplishing this is to have a counter tick off at the start of the post loop, something like:

    <?php $postcounter++; ?>

    Then set your style evaluated against the counter’s value. Again, simplest way is to assign a css class to a PHP variable. Example:

    if( $postcounter <= 3 ) {
    	$postclass = 'first3';
    } elseif( ($postcounter > 3) && ($postcounter <= 13) ) {
    	$postclass = 'next10';
    } else {
    	$postclass = 'therest';

    Finally, where the css class needs to appear:

    <?php echo $postclass; ?>



    You, my friend, are genious.
    thanks a lot for your help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Display posts from TODAY’ is closed to new replies.