1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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 Active Member

    Messages:
    535
    Likes Received:
    38
    Best Answers:
    6
    Trophy Points:
    75
    #2

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

    Code (Text):
    1. <?php
    2. $args=array(
    3.   'orderby' => 'rand',
    4.   'post_type' => 'page',
    5.   'post_status' => 'publish',
    6.   'posts_per_page' => 5,
    7.   'caller_get_posts'=> 1
    8. );
    9. $my_query = null;
    10. $my_query = new WP_Query($args);
    11. if( $my_query->have_posts() ) {
    12.   echo 'List of 5 random pages';
    13.   while ($my_query->have_posts()) : $my_query->the_post(); ?>
    14.     <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    15.     <?php
    16.   endwhile;
    17. }
    18. wp_reset_query();  // Restore global post data stomped by the_post().
    19. ?>
    20.  
    Simple and Clean ;)

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

    Slincon Well-Known Member

    Messages:
    1,257
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    130
  4. themes4all

    themes4all Active Member

    Messages:
    535
    Likes Received:
    38
    Best Answers:
    6
    Trophy Points:
    75
    #4
    themes4all, Jul 7, 2013 IP
    ryan_uk likes this.
  5. IG2010

    IG2010 Well-Known Member

    Messages:
    1,196
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #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 Member

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    43
    #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,196
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #7
    echo 'List of 5 random pages';

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

    ashishkg Member

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    43
    #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