| Author |
Message |
twist
Joined: 05 Jan 2007 Posts: 28
|
|
|
|
Yea I've played with it some more, I definitely am getting blank posts showing up on random_single. No errors and the html code is only generating the <!-- Powered by CuteNews.RU | http://cutenews.ru/ | http://cutephp.com/ --> code.
I have 20+ categories, any thoughts on category specific randomization? Also any possibility to be able to randomize per a time period? For instance Picture of the Day and have it randomize once a day or every hour?
|
|
| Tue Feb 06, 2007 2:44 pm |
|
 |
Guest
|
|
|
Please login to hide the ads.
|
|
|
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2683 Location: Germany |
|
|
|
If you have multiple categories per post I have no idea. Otherwise I might find a solution.
|
|
| Tue Feb 06, 2007 7:20 pm |
|
 |
twist
Joined: 05 Jan 2007 Posts: 28
|
|
|
|
Not multiple categories per post. Just multiple categories in general.
For instance I have:
1. Music
2. Movies
3. Games
4. Sports
5. TV
And then I have 5 or so news posts in each category.
On the home page I want to show 1 random item from the games category.
If I use
 |  | <?php
$number = "1";
$template = "gametemplate";
$category = "3";
$random_single = true;
include("cutenews/show_news.php");
?> |
Then go to the home page and hit refresh, I will randomly get 1 game item. I hit refresh again I get nothing (blank space). I hit refresh again and I get nothing again. I hit refresh again and I get a different game item. Etc. etc.
On the flip side if I use the code &random='true'; it will randomize the order for the last $number which was set. So set $number=4, it will randomize those 4. If I set it to just 1, it will only display the last item with no randomization. (This works as I'm sure it was intended... and I do not get any blank posts).
Make sense?
|
|
| Wed Feb 07, 2007 5:44 pm |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2683 Location: Germany |
|
|
|
1. If you added the following code before, remove it from inc/show.news.php:
 |  | if($random_single){
$table_count = $sql->table_count('news');
$skip = rand(0, $table_count-1);
$random_single = false;
} |
2. Find this:
 |  | $query = $sql->select(array(
'table' => 'news',
'orderby' => $sort,
'join' => array('table' => 'story', 'where' => 'id = post_id'),
'where' => $where,
'limit' => array(($skip ? $skip : 0), $number)
)); |
add below:
 |  | if($random_single){
foreach($sql->select(array('table' => 'news', 'where' => $where)) as $row){
$selected_cat_arr[] = $row['id'];
}
$shuffle = array_rand($selected_cat_arr);
$query = $sql->select(array(
'table' => 'news',
'join' => array('table' => 'story', 'where' => 'id = post_id'),
'where' => array("id = ".$selected_cat_arr[$shuffle])));
$random_single = false;
} |
|
|
| Wed Feb 07, 2007 7:54 pm |
|
 |
twist
Joined: 05 Jan 2007 Posts: 28
|
|
|
|
Flawless!! Nice work! and thank you very much, this was exactly what I needed.
|
|
| Wed Feb 07, 2007 8:16 pm |
|
 |
Dr.Twister
Joined: 23 Apr 2007 Posts: 55
|
|
|
|
New issue on this came up. If I want to include $random_single twice on the same page but with two different categories, then the categories end up in both includes.
For instance :
 |  | <?PHP
$static['category'] = 1;
$static['template'] = 'Template1';
$static['number'] = 1;
$static['random_single'] = 'true';
include("cn/show_news.php");
?>
<?PHP
$static['category'] = 2;
$static['template'] = 'Template2';
$static['number'] = 1;
$static['random_single'] = 'true';
include("cn/show_news.php");
?> |
If I have both of these in a single page then I get some of Category 1 in the Category 2/Template 2 include. I DO NOT get any of Category2 in Template 1 include.
-dt
|
|
| Sun Sep 16, 2007 8:56 pm |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1808 Location: US |
|
|
|
 |  | If you have multiple categories per post I have no idea. Otherwise I might find a solution. |
Oh so THAT's why I've been having trouble with that.
_________________ www.scottdizzle.com uses cnr
last update: 07-22-08: 8:30 pm |
|
| Mon Sep 17, 2007 2:58 am |
|
 |
Yoshiii
Joined: 29 Feb 2008 Posts: 52
|
|
|
|
I use this:
$category = "1,2,3";
$number = 25;
This means i show 25 news (headlines) on the page. When i random, it only randoms between the last 25. But i want him to search through my whole database and show only 25. How can i do that?
|
|
| Sun Mar 02, 2008 2:19 pm |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1808 Location: US |
|
|
|
Are you using either of the $random variables? You might have trouble specifying categories like 1,2,3, I always do.. that's why I use Main Categories and Sub-Categories that way I can show individual subcategories, or all content from a certain topic or main category. But that's beside the point.
Is it still just randomly showing 25 of the latest news kinda shuffled on each page load? I remember mine did that I don't know if I ever figured it out. And when I say I don't remember if I ever figured it out, what I really mean is I don't remember if FI-DD figured that out and shared it with us lol
_________________ www.scottdizzle.com uses cnr
last update: 07-22-08: 8:30 pm |
|
| Sun Mar 02, 2008 5:55 pm |
|
 |
Yoshiii
Joined: 29 Feb 2008 Posts: 52
|
|
|
|
If i specifiy 1 category it also just shows the 25 latest. I hope he has a fix for this 
|
|
| Sun Mar 02, 2008 6:20 pm |
|
 |
alex
Joined: 21 Aug 2008 Posts: 1
|
|
|
|
 |  | New issue on this came up. If I want to include $random_single twice on the same page but with two different categories, then the categories end up in both includes.
For instance :
Code:
<?PHP
$static['category'] = 1;
$static['template'] = 'Template1';
$static['number'] = 1;
$static['random_single'] = 'true';
include("cn/show_news.php");
?>
<?PHP
$static['category'] = 2;
$static['template'] = 'Template2';
$static['number'] = 1;
$static['random_single'] = 'true';
include("cn/show_news.php");
?>
If I have both of these in a single page then I get some of Category 1 in the Category 2/Template 2 include. I DO NOT get any of Category2 in Template 1 include. |
Anybody found a solution for this.
|
|
| Thu Aug 28, 2008 6:25 pm |
|
 |
|