WordPress.org

Ready to get started?Download WordPress

Forums

Displaying Posts in random order (6 posts)

  1. suddensway
    Member
    Posted 2 years ago #

    hi there,

    I wish to display category posts in a random order for all category id's except one which I'd like in the default order.

    I'd rather not use a plug in - not than I can find one that does this anyway. I'm sure there's a bit of php coding I can add/edit that someone out there with a bigger brain than me knows about!

    If someone could help me with this I'd be a very happy bunny and most grateful...

    I'm using Minimal from Elegant Themes and the site is at http://www.allegroartslivemusic.co.uk/

    many thanks
    Kevin

  2. bioshox
    Member
    Posted 2 years ago #

    Hi

    You could use

    <?php query_posts('category=whatever&showposts=5&offset=0&orderby=rand'); ?>

    and that should work.

  3. suddensway
    Member
    Posted 2 years ago #

    Thanks for getting back to me bioshox but I'm not a developer at all and don't really know how to implement this.

    I found a chunk of code in the blog page template that included the query_posts phrase but it was this:

    <?php $cat_query = '';
    						if ( !empty($blog_cats) ) $cat_query = '&cat=' . implode(",", $blog_cats);
    						else echo '<!-- blog category is not selected -->'; ?>
    						<?php
    							$et_paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
    						?>
    						<?php query_posts("showposts=$et_ptemplate_blog_perpage&paged=" . $et_paged . $cat_query); ?>
    						<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    Can you advise on how I could incorporate your suggestion into this at all?

    To confirm, I want the posts to display in random order for posts in all categories except one (and there are many!) so was looking to use the conditional tag such as !in_category( '14' )

    Does that make sense?

    many thanks again for your help
    Kevin

  4. bioshox
    Member
    Posted 2 years ago #

    Hi Kevin,

    try the following

    <?php $cat_query = '';
    						if ( !empty($blog_cats) ) $cat_query = '&cat=' . implode(",", $blog_cats);
    						else echo '<!-- blog category is not selected -->'; ?>
    						<?php
    							$et_paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
    						?>
    						<?php query_posts("showposts=$et_ptemplate_blog_perpage&paged=" . $et_paged . $cat_query."&orderby=rand"; ?>
    						<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  5. suddensway
    Member
    Posted 2 years ago #

    Hi bioshox

    I'm afraid that didn't work - posts are still being displayed by date rather than randomly.

    have you any other ideas on this at all?

    many thanks
    Kevin

  6. bioshox
    Member
    Posted 2 years ago #

    Strange.

    You may need to change your loop, this thread may be of use:

    http://wordpress.org/support/topic/recent-posts-random-order?replies=6

Topic Closed

This topic has been closed to new replies.

About this Topic