Jump to content
Sign in to follow this  
khero

How do i randomize the main loop?

Recommended Posts

khero

I would like to randomize the order of the posts in "theloop", only in the home/posts page. Is there an easy way to assign this order to the homepage, also without affecting search results or category pages? Thanks!

Share this post


Link to post
Share on other sites
Kate
Do you already have your PHP for the query call? You can do it one of two ways: 1) You can add a hook 2) You can add the code to template.postloop.php. (If you go this route, you should copy the file to your Base theme.) Either way, you can add an if statement that checks if it's the home page, and changes the query based on that.

Share this post


Link to post
Share on other sites
khero
Thanks Kate. I don't have the base theme installed. I've only installed Pro and tweaked the CSS from the platform control panel. Can i ask you to be a bit more specific, maybe posting an example of coding for both ways. It's the first time i work with PHP but i have a C++ and ASP background so i know the theory behind it, i'm just lacking the syntax ;)

Share this post


Link to post
Share on other sites
Kate
Sorry... to clarify: you need the code for the randomization, where to put it, or both?

Share this post


Link to post
Share on other sites
Rob
You must add and activate platformbase in order for Platform to work properly and securely. If not, when there's an upgrade, your customizations will be overwritten.

Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
khero
@rangealone i changed some PHP stuff in platformpro/template.postloop.php. you mean it was better if i had created a file called "template.postloop.php" and put it in "platformbase" theme folder, copying the entire original page but with my changes? if so, i think i'm still in time right? @Kate hehehehe, both would be awesome! i know i need to add a "order by = random" kinda thing to the post_query, but i can't find this. other tutorials i found show a different code for the post_query rather than the one i find in platform.

Share this post


Link to post
Share on other sites
Rob
I mean you can copy the default (unchanged) template.postloop.php from wp-content/themes/platformpro and upload it to wp-content/themes/platformbase, then adding your changes, but essentially, what you said works too. Just a different way to go about it. Don't change the file name.

Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
khero
@Kate Hello Kate, any news about that code? ;)

Share this post


Link to post
Share on other sites
khero
This is what WP suggests, but i would need to know if platform changed the default variable names and how to integrate this code in "template.postloop.php" (at least this is the page i think i should be working on):
    5, 'orderby' => 'rand' ); $rand_posts = get_posts( $args ); foreach( $rand_posts as $post ) : ?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×