WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display Recently Updated Posts WordPress (5 posts)

  1. Fask
    Member
    Posted 3 years ago #

    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>
  2. Tara
    Member
    Posted 3 years ago #

  3. Fask
    Member
    Posted 3 years ago #

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

  4. Fask
    Member
    Posted 3 years ago #

    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; ?>
  5. Tara
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic