Kieran Posted February 25, 2010 Report Share Posted February 25, 2010 Hey there, My VA has three/four separate divisions, and each of them would like their own news category. The thing is, phpVMs does not have an option for this at the moment. I can simply add a column to the database, but can somebody point me in the right direction as to how to edit the admin module to display a drop-down with possible menu categories, and to display news from only one category on certain pages? If all else fails then I could use manual SQL queries but I'd prefer the proper method. Thank you, Kieran Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted February 26, 2010 Administrators Report Share Posted February 26, 2010 Poke around in the SiteCMS.class.php in core/common. you can modify those to include a category id, or an airline id. you can add in a drop-down with the airlines list, so that would simply that. so you'd just have to pass the $this->post->airlineid variable through to the query 1 Quote Link to comment Share on other sites More sharing options...
Kieran Posted February 28, 2010 Author Report Share Posted February 28, 2010 Right I have a function like this (I have successfully coded the add-news section): public static function GetNewsItemByCategory($category,$limit) { if (!$limit) { return DB::get_results('SELECT *, UNIX_TIMESTAMP(postdate) AS postdate FROM '.TABLE_PREFIX.'news WHERE category=`'.$category.'`'); } elseif ($limit) { return DB::get_results('SELECT *, UNIX_TIMESTAMP(postdate) AS postdate FROM '.TABLE_PREFIX.'news WHERE category=`'.$category.'` LIMIT '. $limit); } } Now how would I integrate this into my page, so that I could echo all of the news from a specific category? Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted February 28, 2010 Administrators Report Share Posted February 28, 2010 I simplified it a bit for you, if you don't mind. public static function GetNewsItemByCategory($category,$limit) { $sql = 'SELECT *, UNIX_TIMESTAMP(postdate) AS postdate FROM '.TABLE_PREFIX.'news WHERE category=`'.$category.'`'; if (!empty($limit)) { $sql .= ' LIMIT '.$limit; } return DB::get_results($sql); } You can call it as (assuming you put it in SiteCMS, or even better, just create a new dataclass for it so it doesnt get overwritten - to do that just follow the same format as the other classes in there, ClassName.class.php, then inside that is class ClassName { }... in fact, creating a class like that called CustomQueries (so CustomQueries.class.php, and inside class CustomQueries{ } ) to put all your custom code so it's not overwritten in an update is probably a good idea) $news = SiteCMS::getNewsItemByCategory($category, 1); 1 Quote Link to comment Share on other sites More sharing options...
Kieran Posted February 28, 2010 Author Report Share Posted February 28, 2010 Thank you for that, I now have a Custom.class.php as well. I have this code on my page now: $news = Custom::GetNewsItemByCategory('notam', 1); But I'm stuck as to what to do with it, an attempt at a For-each loop displays an 'Invalid Argument Supplied' error. Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted March 1, 2010 Administrators Report Share Posted March 1, 2010 Thank you for that, I now have a Custom.class.php as well. I have this code on my page now: $news = Custom::GetNewsItemByCategory('notam', 1); But I'm stuck as to what to do with it, an attempt at a For-each loop displays an 'Invalid Argument Supplied' error. After that line, put a DB::debug() statement, like: $news = Custom::GetNewsItemByCategory('notam', 1); DB::debug(); There might be an error in the SQL, but it will tell you exactly what was returned from the database Quote Link to comment Share on other sites More sharing options...
Kieran Posted March 1, 2010 Author Report Share Posted March 1, 2010 Got it working now, the DB::debug was empty but I relaised that the ` character should really have been " or ' . However, it doesn't seem to be ordering the query results correctly? It always seems to return the FIRST post and never the most recent. Quote Link to comment Share on other sites More sharing options...
Kieran Posted March 1, 2010 Author Report Share Posted March 1, 2010 EDIT: Used an ORDER BY to fix that out... Nabeel, we could do with you expertise over on the phpBB AutoRegistration Dev Thread, Thanks... Kieran Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.