GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Wordpress: Random posts & Pagination (https://gfy.com/showthread.php?t=1077290)

The Dawg 08-08-2012 05:38 AM

Wordpress: Random posts & Pagination
 
I noticed if I order the post by random that Wordpress does not remember the posts displayed and repeats entries on the 2nd, 3rd, etc pages.

Whats the best solution to shuffle the posts in a category, but make sure that they dont repeat?

Thanks

fris 08-08-2012 06:10 AM

maybe something along these lines

Code:

session_start();

add_filter('posts_orderby', 'edit_posts_orderby');

function edit_posts_orderby($orderby_statement) {

    $seed = $_SESSION['seed'];
    if (empty($seed)) {
      $seed = rand();
      $_SESSION['seed'] = $seed;
    }

    $orderby_statement = 'RAND('.$seed.')';
    return $orderby_statement;
}


fris 08-08-2012 06:12 AM

also have a look at this http://wordpress.mcdspot.com/2011/12...-set-of-posts/

The Dawg 08-08-2012 08:47 AM

Quote:

Originally Posted by fris (Post 19110091)
maybe something along these lines

Code:

session_start();

add_filter('posts_orderby', 'edit_posts_orderby');

function edit_posts_orderby($orderby_statement) {

    $seed = $_SESSION['seed'];
    if (empty($seed)) {
      $seed = rand();
      $_SESSION['seed'] = $seed;
    }

    $orderby_statement = 'RAND('.$seed.')';
    return $orderby_statement;
}


I found this post also.

I added it to the functions file and it works - but, it affects everything including the listings in the admin area.

Quote:

Originally Posted by fris (Post 19110093)

Where would I stick this code?

fris 08-08-2012 12:09 PM

Quote:

Originally Posted by The Dawg (Post 19110349)
I found this post also.

I added it to the functions file and it works - but, it affects everything including the listings in the admin area.



Where would I stick this code?

you could check for is_admin() and whatever else, would need to know where you are putting the random bit, so you can only show it there.

CurrentlySober 08-08-2012 12:11 PM

Quote:

Originally Posted by The Dawg (Post 19110349)
Where would I stick this code?

So, so, so... Tempting :winkwink:

V_RocKs 08-08-2012 12:21 PM

Get picks if you stick it up your ass


All times are GMT -7. The time now is 04:07 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123