wordpress question

sk8tavou

Elite Member
Joined
Aug 28, 2011
Messages
1,797
Reaction score
1,435
Hello there forum :)

i have a question! i have a blog and i want all my posts everytime a user visit my sites to be in random order everytime!

i found some plugins but all of them displays the random posts in the sidebar :(
 
You would need some script that repost the posts i belive

Since the posts are bound to date and time, older posts want show up before newer posts
 
You might need to make some changes to the core Wordpress codebase, so that instead of querying and ordering by date, it's randomly ordered. I'll see if I can investigate further and show you the exact line(s) of code to modify.
 
If you will be able to get the plugins or a script to make it work the way you want it. Please let us know its effect in rankings and CTR....
 
In your index.php "loop", you want to include the following custom query:

PHP:
<?php query posts( 'orderby=rand' ); ?>

In TwentyEleven, the start of the loop looks like this:

PHP:
<?php if ( have_posts() ) : ?>

<?php twentyeleven_content_nav( 'nav-above' ); ?>

<?php /* Start the Loop */ ?>
	<?php while ( have_posts() ) : the_post(); ?>

		<?php get_template_part( 'content', get_post_format() ); ?>

	<?php endwhile; ?>

	<?php twentyeleven_content_nav( 'nav-below' ); ?>

<?php else : ?>

Change it to:

PHP:
<?php query posts( 'orderby=rand' ); ?>
<?php if ( have_posts() ) : ?>

<?php twentyeleven_content_nav( 'nav-above' ); ?>

<?php /* Start the Loop */ ?>
	<?php while ( have_posts() ) : the_post(); ?>

		<?php get_template_part( 'content', get_post_format() ); ?>

	<?php endwhile; ?>

	<?php twentyeleven_content_nav( 'nav-below' ); ?>

<?php else : ?>
 
Last edited:
In your index.php "loop", you want to include the following custom query:

PHP:
<?php query posts( 'orderby=rand' ); ?>

because im new in wordpress can you tell me what steps i have to follow to get to the index.php? and i will post the query in any place?
 
because im new in wordpress can you tell me what steps i have to follow to get to the index.php? and i will post the query in any place?
I think you can put it right at the top of your wordpress theme index.php.

So go to your theme folder via ftp, download the index.php, add the line, save the file and upload it again
 
because im new in wordpress can you tell me what steps i have to follow to get to the index.php? and i will post the query in any place?

You have to post the query before the start of the loop...so before the "<?php if ( have_posts() ) : ?>"

Step #1: Get an FTP Software. I recommmend Filezilla for Windows and Coda for Mac.

Step #2: Navigate through WordPress by going to: wp-content > themes > THEME-FOLDER > index.php

Step #3: Open up the index.php file and edit the section I just spoke about. (it's not a big file so you shouldn't get too lost.)
 
I think you can put it right at the top of your wordpress theme index.php.

So go to your theme folder via ftp, download the index.php, add the line, save the file and upload it again

thanks a lot i will try it later and i will post :)
 
I think you can put it right at the top of your wordpress theme index.php.

So go to your theme folder via ftp, download the index.php, add the line, save the file and upload it again

I guess you could...but it's just bad practice. If you ever wanted to change something, have a coder work on your site, or have multiple loops within a single file...your going to run into issues.
 
i opened the index.php but didnt find the <?php if ( have_posts() ) : ?>
:(
 
In your index.php "loop", you want to include the following custom query:

PHP:
<?php query posts( 'orderby=rand' ); ?>

In TwentyEleven, the start of the loop looks like this:

PHP:
<?php if ( have_posts() ) : ?>
 
<?php twentyeleven_content_nav( 'nav-above' ); ?>
 
<?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
 
        <?php get_template_part( 'content', get_post_format() ); ?>
 
    <?php endwhile; ?>
 
    <?php twentyeleven_content_nav( 'nav-below' ); ?>
 
<?php else : ?>

Change it to:

PHP:
<?php query posts( 'orderby=rand' ); ?>
<?php if ( have_posts() ) : ?>
 
<?php twentyeleven_content_nav( 'nav-above' ); ?>
 
<?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
 
        <?php get_template_part( 'content', get_post_format() ); ?>
 
    <?php endwhile; ?>
 
    <?php twentyeleven_content_nav( 'nav-below' ); ?>
 
<?php else : ?>

Always great to have good coders around. thanks alot for the script fix.
 
Download the "Advanced Random Post" plugin by Daniele Salamina ....easy :) Got this setup on one of my sites and it works a treat :D
 
Back
Top