WordPress.org

Ready to get started?Download WordPress

Forums

Display posts from TODAY (10 posts)

  1. Ignacio
    Member
    Posted 6 years ago #

    Hi!
    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!

  2. Kafkaesqui

    Posted 6 years ago #

    http://wordpress.org/support/topic/98090#post-488635

    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.

  3. Ignacio
    Member
    Posted 6 years ago #

    thanks a lot!

    i´ll try this right now!

    can´t believe i missed that in my searches

  4. Ignacio
    Member
    Posted 6 years ago #

    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 :(

  5. Kafkaesqui

    Posted 6 years ago #

    *sigh*

    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).

  6. Kafkaesqui

    Posted 6 years ago #

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

    <?php
    	/* 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).

  7. Ignacio
    Member
    Posted 6 years ago #

    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 :D

    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!

  8. Ignacio
    Member
    Posted 6 years ago #

    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() ) {
    ?

  9. Kafkaesqui

    Posted 6 years ago #

    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:

    <?php
    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; ?>

  10. Ignacio
    Member
    Posted 6 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic