Plugin required on wordpress.org

Discussion in 'WordPress' started by IG2010, Jul 7, 2013.

  1. #1
    Hi,

    I am looking for a plugin that display random Pages on a widget in sidebar, trying to search on wordpress.org but only finding for posts

    anyone heard about this plugin?

    thanks
     
    IG2010, Jul 7, 2013 IP
  2. themes4all

    themes4all Well-Known Member

    Messages:
    662
    Likes Received:
    47
    Best Answers:
    6
    Trophy Points:
    100
    #2

    In fact you don't need a Plugin, just a Little code, like this :

    <?php
    $args=array(
      'orderby' => 'rand',
      'post_type' => 'page',
      '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() ) {
      echo 'List of 5 random pages';
      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().
    ?>
    
    Code (markup):
    Simple and Clean ;)

    Goodluck
     
    themes4all, Jul 7, 2013 IP
    IG2010 and ryan_uk like this.
  3. Slincon

    Slincon Well-Known Member

    Messages:
    1,319
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    180
  4. themes4all

    themes4all Well-Known Member

    Messages:
    662
    Likes Received:
    47
    Best Answers:
    6
    Trophy Points:
    100
    #4
    themes4all, Jul 7, 2013 IP
    ryan_uk likes this.
  5. IG2010

    IG2010 Well-Known Member

    Messages:
    1,424
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    195
    #5
    ok, thanks a lot, but waht about dedicated pages 'like that page that one that one but not that one' ^^
     
    IG2010, Jul 7, 2013 IP
  6. ashishkg

    ashishkg Active Member

    Messages:
    233
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    68
    #6
    You will add this code in sidebar, this will hep you
    <ul>

    <?php query_posts('posts_per_page=5&orderby=rand'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a> </li>
    <?php endwhile; ?>
    <?php endif; ?>
    </ul>
     
    ashishkg, Jul 8, 2013 IP
  7. IG2010

    IG2010 Well-Known Member

    Messages:
    1,424
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    195
    #7
    echo 'List of 5 random pages';

    do you mean I enter page ID's?
     
    IG2010, Jul 8, 2013 IP
  8. ashishkg

    ashishkg Active Member

    Messages:
    233
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    68
    #8
    No that line you need to remove <?php echo 'list of 5 random pages' ?> You see the 'post_per_page'=> 5 that is mean, how many pages you want to display. so only change here 'post_per_page'=> 5 .
     
    ashishkg, Jul 8, 2013 IP