Today! I had a breakthrough and I think I have found the solution!
What does it do?
In the include, where you can choose categories, if you put for example: 1,5
It will show all the news from category 1 and all the news from category 5
without any connection between the categories, it will just sort them by date (or whatever you chose)..
Now, have you ever wanted to be able to choose 1,5 and only posts that have been
posted to these two categories 1 AND 5 (even if posted to more other categories too!) will show?
Now you can!!
Phew, it took me some time understanding how to sql that so it will work 100% lol
Installation
Open inc/show.news.php
Find:
- Code: Select all
$where[] = 'and';
foreach($allow_categories as $single_cat){
$where[] = 'category =~ %'.$single_cat.'%';
$where[] = 'or';
}
Replace with:
- Code: Select all
//DarkSlim's Hack for $bothcat - showing only posts that been posted in both two chosen categories
if($bothcat == 'true'){
$where[] = 'and';
$cat1 = $allow_categories[0];
$cat2 = $allow_categories[1];
$where[] = 'category =~ '.$cat2.','.$cat1.'';
$where[] = 'or';
$where[] = 'category =~ '.$cat1.','.$cat2.'';
$where[] = 'or';
$where[] = 'category =~ '.$cat1.',%,'.$cat2.'';
$where[] = 'or';
$where[] = 'category =~ '.$cat2.',%,'.$cat1.'';
$where[] = 'or';
$where[] = 'category =~ %,'.$cat2.','.$cat1.'';
$where[] = 'or';
$where[] = 'category =~ %,'.$cat2.',%,'.$cat1.'';
$where[] = 'or';
$where[] = 'category =~ %,'.$cat2.',%,'.$cat1.',%';
$where[] = 'or';
$where[] = 'category =~ '.$cat2.',%,'.$cat1.',%';
$where[] = 'or';
$where[] = 'category =~ '.$cat2.','.$cat1.',%';
$where[] = 'or';
$where[] = 'category =~ %,'.$cat1.','.$cat2.'';
$where[] = 'or';
$where[] = 'category =~ %,'.$cat1.',%,'.$cat2.'';
$where[] = 'or';
$where[] = 'category =~ %,'.$cat1.',%,'.$cat2.',%';
$where[] = 'or';
$where[] = 'category =~ '.$cat1.',%,'.$cat2.',%';
$where[] = 'or';
$where[] = 'category =~ '.$cat1.','.$cat2.',%';
$where[] = 'or';
} else {
//If $bothcat is not used, this is the normal category check
$where[] = 'and';
foreach($allow_categories as $single_cat){
$where[] = 'category =~ %'.$single_cat.'%';
$where[] = 'or';
}
}
That's it, now in your include you just need to choose
the categories - don't forget you can choose only 2!
The code can be changed to check for 3 too, but for now I'm using only 2.
The last thinng you need to add for it to work, add in your
include:
$bothcat = 'true';
As long as $bothcat is true in that include it will do my new both categories check!
Here is an Example include:
- Code: Select all
<?php
$template = 'MyTemplate';
$number = 5;
$category = '1,5';
$bothcat = 'true';
include $cutepath.'/show_news.php';
?>
Edit: New code, fixed some 'holes' in the code
that might happen when the user have more than 9 categories
now it's near perfect.
Hope it helps, if you are using it and want to
donate so I can keep making CNR fixes, hacks and addons
there's a link in my signature, thanks!
