1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

wordpress question

Discussion in 'Blogging' started by sk8tavou, Sep 5, 2011.

  1. sk8tavou

    sk8tavou Senior Member

    Joined:
    Aug 28, 2011
    Messages:
    1,130
    Likes Received:
    1,333
    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 :(
     
  2. ronegraT

    ronegraT Power Member

    Joined:
    Dec 29, 2010
    Messages:
    620
    Likes Received:
    101
    Occupation:
    sleeping
    Location:
    Sweden
    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
     
  3. Crazy

    Crazy Jr. Executive VIP

    Joined:
    Jun 13, 2009
    Messages:
    640
    Likes Received:
    319
    Occupation:
    VB, C#, XHTML, CSS, PHP, MySQL, JavaScript, jQuery
    Location:
    Everywhere
    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.
     
  4. IPXPRT

    IPXPRT Jr. VIP Jr. VIP

    Joined:
    Oct 25, 2010
    Messages:
    3,631
    Likes Received:
    1,230
    Home Page:
    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....
     
  5. blackhatcodex

    blackhatcodex BANNED BANNED

    Joined:
    Aug 28, 2011
    Messages:
    144
    Likes Received:
    248
    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 : ?>
     
    • Thanks Thanks x 4
    Last edited: Sep 5, 2011
  6. sk8tavou

    sk8tavou Senior Member

    Joined:
    Aug 28, 2011
    Messages:
    1,130
    Likes Received:
    1,333
    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?
     
  7. wickedguy

    wickedguy Supreme Member

    Joined:
    Jul 22, 2009
    Messages:
    1,402
    Likes Received:
    1,379
    Location:
    BHW--> South Africa
    Home Page:
    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
     
  8. blackhatcodex

    blackhatcodex BANNED BANNED

    Joined:
    Aug 28, 2011
    Messages:
    144
    Likes Received:
    248
    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.)
     
  9. sk8tavou

    sk8tavou Senior Member

    Joined:
    Aug 28, 2011
    Messages:
    1,130
    Likes Received:
    1,333
    thanks a lot i will try it later and i will post :)
     
  10. blackhatcodex

    blackhatcodex BANNED BANNED

    Joined:
    Aug 28, 2011
    Messages:
    144
    Likes Received:
    248
    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.
     
  11. sk8tavou

    sk8tavou Senior Member

    Joined:
    Aug 28, 2011
    Messages:
    1,130
    Likes Received:
    1,333
    i opened the index.php but didnt find the <?php if ( have_posts() ) : ?>
    :(
     
  12. beeHWfan

    beeHWfan Regular Member

    Joined:
    Aug 30, 2010
    Messages:
    452
    Likes Received:
    225
    Occupation:
    do it all
    Location:
    US
    Home Page:
    Always great to have good coders around. thanks alot for the script fix.
     
  13. blackhatcodex

    blackhatcodex BANNED BANNED

    Joined:
    Aug 28, 2011
    Messages:
    144
    Likes Received:
    248
    What theme are you using? It may be pulling from the loop.php
     
  14. seraphin

    seraphin Newbie

    Joined:
    Sep 4, 2010
    Messages:
    18
    Likes Received:
    8
    Location:
    UK
    Home Page:
    Download the "Advanced Random Post" plugin by Daniele Salamina ....easy :) Got this setup on one of my sites and it works a treat :D