Support » Fixing WordPress » Show recently updated posts in sidebar

  • Resolved Dr. Irfan

    (@drirfantariq)


    Hello there, I have been trying to show 5 recently modified posts in my wordpress blog but the code doesn’t seem to work. I add this code in the ‘text’ widget in the sidebar but it doesn’t work.

    Here is the code:

    <?php
    $args=array(
      'orderby'=> 'modified',
      'order' => 'ASC',
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 5,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Any idea what’s wrong here?

    Here is the link to my website: http://androidgameapks.com/the-simpsons-tapped-out-cheat-apk-unlimited-money-xp-and-donuts/

    Notice the code on the right sidebar on the top

Viewing 2 replies - 1 through 2 (of 2 total)
  • bradchando

    (@bradchando)

    You can’t execute php code inside the standard text widget. That is why this is not working for you.

    If you don’t feel up to creating your own widget to handle this, you could probably use a plugin like:

    https://wordpress.org/plugins/php-code-widget/

    I don’t have experience with this type of plugin, but it would be a quick fix. Just be aware of the security considerations mentioned in the plugin’s description.

    Hope this helps!

    Brad

    Dr. Irfan

    (@drirfantariq)

    Thanks a lot bradchando. It is now working perfectly.

    Nobody else, except me, has the access to my website, so I don’t think there would be any security threat.

    Thanks again. I had wasted a lot of time on this.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show recently updated posts in sidebar’ is closed to new replies.