Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
How to Display Discussion from all the Categories except one on Discussions page?
sahotataran
✭✭✭
Best Answers
-
x00 MVPNested sql is rarely a good idea especial in an IN very slow, and often not configured in mySQL, also if you look in the discussion model they are not using an JOIN instead they zip the categories data to the discussion data programmatically after the discussion dat has bee got. This will be for performance reasons.
SO for this reason, it would be better to simply remove the offending data before it is renderered.
Something like:public function DiscussionsController_Render_Before(&$Sender){
if (strtolower($Sender->RequestMethod) != 'index') return;
foreach (CategoryModel::Categories() As $Category) {
if ($Category['Name'] == 'Blog'){
$ID = $Category['CategoryID'];
break;
}
}
if(!$ID) return;
$Discussions = $Sender->Data('Discussions');
foreach($Discussions As &$Discussion){
if($Discussion['CategoryID']==$ID){
$Discussion = null;
}
}
$Discussions = array_filter($Discussions);
$Sender->SetData('Discussions',$Discussions);
}grep is your friend.
0 -
x00 MVPSorry this is more like it
public function DiscussionsController_Render_Before(&$Sender){
if (strtolower($Sender->RequestMethod) != 'index') return;
$Discussions = $Sender->Data('Discussions');
$DiscussionsFiltered =array();
foreach($Discussions As $Discussion ){
if($Discussion->Category!=='Blog'){
$DiscussionsFiltered[]=$Discussion;
}
}
$DiscussionsFiltered = new Gdn_DataSet($DiscussionsFiltered);
$Sender->DiscussionData =$DiscussionsFiltered;
$Sender->Data('Discussions',$DiscussionsFiltered);
}grep is your friend.
0
Answers
cheers
There was an error rendering this rich post.
Not sure how that could be done, but I'm assuming when the query is made to mysql, to display all discussions, it must be specified to omit the specific category, with some kind of 'if' clause.
If the mysql query needs to be altered to omit a specific category, it's not that easy to resolve. I'll give it some thought, sahotataran.
There was an error rendering this rich post.
Thanks guys
There was an error rendering this rich post.
sahotataran can you give me 2 examples please? Let's do an example with PHP scripts.
Your category on NillaBlog is "Forum Scripts". The forums are "Vanilla", "PhpBB" and "SMF". Tell what you need in which situation :-)
There was an error rendering this rich post.
say -> i have 4 categories named NEWS, ARTICLES, FEATURED, OTHER
using NillaBlog i have Displayed ARTICLES category page as BLOG and its url categories/articles - i am using as home page.
u know how on discussions page /DISCUSSIONS - all the discussions are listed - which are from NEWS, ARTICLES, FEATURED, OTHER
but i dont want to display ARTICLES in this list of DISCUSSIONS
so i wanted to know if that is possible
There was an error rendering this rich post.
There was an error rendering this rich post.
Experiment with this SQL a bit, it's not the most perfect SQL I've written.
You can hardcode the category ID of the Articles category. You can replace the "NOT IN" with something else.
There was an error rendering this rich post.
There was an error rendering this rich post.
SO for this reason, it would be better to simply remove the offending data before it is renderered.
Something like:
grep is your friend.
grep is your friend.
get the category id before the discussions query is built. Then add the where clause to the query builder (no join). Then this will return the results you want.
grep is your friend.
There was an error rendering this rich post.
DiscussionController_Index_Before
store the category Id in a class variable then with
DiscussionModel_BeforeGet_Handler
add the where
$Sender->SQL->Where('d.CategoryID <>', $this->BlogCategoryID);
This would produce better results. This all stimulates on
if(strtolower($Sender->RequestMethod) != 'index') return;
if (!isset($this->BlogCategoryID)) return;
respectively
grep is your friend.
i did something like this on my home page but its not loading DISCUSSIONS VIEW and gives error as can you please help me with it????
Thanks in advance
There was an error rendering this rich post.
grep is your friend.
i check if the URL is my home page and if its home page then
line wise explanation
1.new discussion model
2. whereas option which we pass to Get method in DiscussionModel (i am displaying all discussions except a particular category categoryID)
3. get result from Get function in DiscussionModel which returns me recently posted 10 discussions which are not from particular CATEGORY and save its result in variable $discussions
4. create a new controller for discussionsController
5. i pass its DiscussionsData as result from my above DiscussionModel resultset
6. then i try to load view 'discussions'
7. render it - but the above error
There was an error rendering this rich post.
Thanks x00
There was an error rendering this rich post.
Please consider contributing this as a feature to the NillaBlog project. I suspect others may want this functionality as well.
If you don't know how to pull the code and submit a patch, try to come up with a working example plugin for your forum where you have it working and submit the working code as part of a ticket. I'll see if I can work it into the settings of the project so that others may benefit.
There was an error rendering this rich post.