• Resolved Fask

    (@fask)


    Floating around the Internet is a piece of PHP code that is designed to display recently updated posts/pages in WordPress. After submitting a request to experts-exchange for assistance, within moments, I had the raw code I needed.

    However, the original PHP code still didn’t work for my WordPress installation. After some tweaks and a lot of additional bells and whistles, I had managed to piece together the code needed to only display recently updated posts.

    At this point I ask for help to show only posts from a specific category. Is it possible to show only posts from a specific category? Can you help?

    this is the current code:

    <div class="statistics">
    <?php
    $today = current_time('mysql', 1);
    $howMany = 10; //Number of posts you want to display
    if ($recentposts = $wpdb->get_results("SELECT ID, post_title, post_modified FROM $wpdb->posts    WHERE post_status = 'publish' AND post_type = 'post' AND post_name NOT LIKE  '%revision%' AND post_name NOT LIKE '%autosave%' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")) :
    ?>
    <h2><?php _e('ULTIME SERIE TV AGGIORNATE'); ?></h2>
    <ul>
    <?php
    foreach($recentposts as $post) {
    if ($post->post_title == '') {
    $post->post_title = sprintf(__('Post #%s'), $post->ID);
    }
    /* If no post title exists one will be assigned to it. */
    echo "<li><a href='".get_permalink($post->ID)."'>";
    echo mysql2date('d/m/Y', $post->post_modified);
    echo "&nbsp;-&nbsp;";
    echo $post->post_title;
    echo '</a></li>';
    }
    ?>
    </ul>
    <?php endif; ?>
    </div>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p

    (@t-p)

    Thread Starter Fask

    (@fask)

    I thank you for the alert but there is without solution to the problem

    Thread Starter Fask

    (@fask)

    ok I found the solution:

    <div class="statistics">
    <?php
    $today = current_time('mysql', 1);
    $howMany = 10; //Number of posts you want to display
    if ($recentposts = $wpdb->get_results("SELECT ID, post_title, post_modified FROM $wpdb->posts    WHERE post_status = 'publish' AND post_type = 'post' AND post_name NOT LIKE  '%revision%' AND post_name NOT LIKE '%autosave%' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")) :
    ?>
    <h2><?php _e('ULTIME REVISIONI'); ?></h2>
    <ul>
    <?php $args = array('category' => '4');
    $recent_posts = wp_get_recent_posts($args);
    foreach ($recent_posts as $post) {
    if ($post["post_title"] == ''){ $post["post_title"] = sprintf(__('Post #%s'), $post["ID"]);
    }
    ?>
    <li><a href='<?php echo get_permalink($post["ID"]) ?>'>
    <?php echo mysql2date('d/m/Y', $post["post_modified"]) ?>
    &nbsp;-&nbsp;
    <?php echo $post["post_title"] ?>
    </a></li> <?php } ?>
    </ul>
    </div>
    <?php endif; ?>
    Moderator t-p

    (@t-p)

    excellent! 🙂

    Please mark thread as “resolved” using the dropdown in the right panel so that:
    – others with similar problem can see it as “resolved” and will read this thread for help if they have similar problem.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display Recently Updated Posts WordPress’ is closed to new replies.