-
AuthorPosts
-
sjmorris Friend
sjmorris
- Join date:
- March 2009
- Posts:
- 22
- Downloads:
- 0
- Uploads:
- 3
- Thanks:
- 5
- Thanked:
- 2 times in 1 posts
November 16, 2009 at 6:13 pm #146085Hi,
I really like the look of ja_news2 and I would like it to only show categories from selected sections that have the newest articles.
So for example, right now I have it showing a 5 sections (with three rows each) that have multiple categories in them, but it only displays the first three categories from each section – the others remain hidden unless I configure it to show more columns. I’d like it to show the three categories with the most recent posts in them, from newest to oldest.
Possible?
S
zorroh Friendzorroh
- Join date:
- November 2006
- Posts:
- 422
- Downloads:
- 20
- Uploads:
- 43
- Thanks:
- 88
- Thanked:
- 80 times in 1 posts
November 17, 2009 at 3:04 am #323850i also need this feature. i posted some weeks ago same idea here: http://www.joomlart.com/forums/topic/ja-news-2-order-automatically-new-categories-to-be-first-on-front-page/
1 user says Thank You to zorroh for this useful post
sjmorris Friendsjmorris
- Join date:
- March 2009
- Posts:
- 22
- Downloads:
- 0
- Uploads:
- 3
- Thanks:
- 5
- Thanked:
- 2 times in 1 posts
December 9, 2009 at 9:42 am #326174Bump.. just wondering if anyone can help?
sjmorris Friendsjmorris
- Join date:
- March 2009
- Posts:
- 22
- Downloads:
- 0
- Uploads:
- 3
- Thanks:
- 5
- Thanked:
- 2 times in 1 posts
December 10, 2009 at 10:29 pm #326313Got a programmer savvy guy to fix this. Joomlart devs, I’m disappointed you couldn’t help us out but at least add this to the next rev of the code:
In helper.php:
FIND:
$query = “SELECT `id`, `title`, `description`, CASE WHEN CHAR_LENGTH(`alias`) THEN CONCAT_WS(“:”, `id`, `alias`) ELSE `id` END as `slug` FROM `#__categories` s WHERE published = 1 and section=” . ( int ) $sid . $where;
$query .= ” ORDER BY s.ordering ASC”; //$query .= ” ORDER BY s.id ASC”;
REPLACE WITH:
$query = “SELECT s.id as id, s.title as title, s.description as description, CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(‘:’, s.id, s.alias) ELSE s.id END as slug FROM jos_content a, jos_categories s WHERE a.catid = s.id AND s.section={$sid} {$where} GROUP BY a.catid ORDER BY MAX(a.created) DESC”;
Works for me.
S
1 user says Thank You to sjmorris for this useful post
kryptos Friendkryptos
- Join date:
- November 2009
- Posts:
- 105
- Downloads:
- 0
- Uploads:
- 8
- Thanks:
- 9
- Thanked:
- 13 times in 9 posts
December 23, 2009 at 9:55 am #327267<em>@sjmorris 156479 wrote:</em><blockquote>
$query .= ” ORDER BY s.ordering ASC”; //$query .= ” ORDER BY s.id ASC”;</blockquote>
there is no such a string in my helper.php file :confused:
sjmorris Friendsjmorris
- Join date:
- March 2009
- Posts:
- 22
- Downloads:
- 0
- Uploads:
- 3
- Thanks:
- 5
- Thanked:
- 2 times in 1 posts
December 23, 2009 at 10:05 am #327270/joomla/modules/mod_janews2/helper.php
Not sure what else to do here – unless they have updated this module since I downloaded it. PM me your email and I’ll send you a copy of mine.
kryptos Friendkryptos
- Join date:
- November 2009
- Posts:
- 105
- Downloads:
- 0
- Uploads:
- 8
- Thanks:
- 9
- Thanked:
- 13 times in 9 posts
December 23, 2009 at 10:08 am #327272I have 1.3 version.
I’ll check out the newest one…edit:
i’ve just downloaded version 1.4, but no, still there is no such a string in helper.php file.
Saguaros ModeratorSaguaros
- Join date:
- September 2014
- Posts:
- 31405
- Downloads:
- 237
- Uploads:
- 471
- Thanks:
- 845
- Thanked:
- 5346 times in 4964 posts
December 25, 2009 at 4:51 am #327473it’s at line 421 inside the loadCategories function, please try to find again 🙂
January 4, 2010 at 5:06 pm #328165I have inserted the code as recommended for the function (see below):
function loadCategories($sid) {
$categories = array ();
$catids = $this->getUserSetting ( $sid, ‘categories’ );$where = ”;
$limit = 0;
if ($catids) {
if (is_array ( $catids ))
$where .= ” AND `id` in (” . implode ( ‘,’, $catids ) . “)”;
} else {
if (is_array ( $this->getUserSetting ( $sid ) ))
$where = ” AND 0″;
else
$limit = ( int ) $this->get ( ‘cols’, 2 );
}$db = & JFactory::getDBO ();
/*
Commented out on 4 Jan 2010 and inserted code from http://www.joomlart.com/forums/topic/ja_news2-only-show-categories-with-new-articles/
$query = “SELECT `id`, `title`, `description`, CASE WHEN CHAR_LENGTH(`alias`) THEN CONCAT_WS(“:”, `id`, `alias`) ELSE `id` END as `slug` FROM `#__categories` s WHERE published = 1 and section=” . ( int ) $sid . $where;
*/
$query = “SELECT s.id as id, s.title as title, s.description as description, CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(‘:’, s.id, s.alias) ELSE s.id END as slug FROM jos_content a, jos_categories s WHERE a.catid = s.id AND s.section={$sid} {$where} GROUP BY a.catid ORDER BY MAX(a.created) DESC”;
$db->setQuery ( $query, 0, $limit );
$rows = $db->loadObjectList ( ‘id’ );
foreach ( $rows as $cid => $row ) {
$obj = new stdclass ( );
$obj->category = $row;
$categories [] = $obj;
}
return $categories;
}It works perfectly for some sections. However on two sections I am getting the error message on the Frontpage:
“Warning: Invalid argument supplied for foreach() in C:xampphtdocsbtm_29_dec_2009modulesmod_janews2helper.php on line 428”Line 428 is: foreach ( $rows as $cid => $row ) {
The section title is displayed.
Any ideas on this as there is nothing special about the sections causing the error as they worked OK with the original code that I have now commented out.
glitter Friendglitter
- Join date:
- March 2010
- Posts:
- 12
- Downloads:
- 0
- Uploads:
- 3
- Thanked:
- 1 times in 1 posts
September 16, 2010 at 10:43 pm #355745Hello,
I’m very intrested to ordering and showing categories that have the newest articles only (Category order will change as has newest article). That will make the news more interactive in the categories.
The code is working but I’m also have same error:
Warning: Invalid argument supplied for foreach() in …modules/mod_janews2/helper.php on line 431
( in my file 431 = foreach ( $rows as $cid => $row ) { )So, please could you solve it?
Saguaros ModeratorSaguaros
- Join date:
- September 2014
- Posts:
- 31405
- Downloads:
- 237
- Uploads:
- 471
- Thanks:
- 845
- Thanked:
- 5346 times in 4964 posts
September 17, 2010 at 7:11 am #355777<em>@glitter 194297 wrote:</em><blockquote>Hello,
I’m very intrested to ordering and showing categories that have the newest articles only (Category order will change as has newest article). That will make the news more interactive in the categories.
The code is working but I’m also have same error:
Warning: Invalid argument supplied for foreach() in …modules/mod_janews2/helper.php on line 431
( in my file 431 = foreach ( $rows as $cid => $row ) { )So, please could you solve it?</blockquote>
Hello, please try following to the thread #4 http://www.joomlart.com/forums/topic/ja_news2-only-show-categories-with-new-articles/#post-326313
Sherlock FriendSherlock
- Join date:
- September 2014
- Posts:
- 11453
- Downloads:
- 0
- Uploads:
- 88
- Thanks:
- 221
- Thanked:
- 2478 times in 2162 posts
September 17, 2010 at 10:49 am #355811<em>@glitter 194297 wrote:</em><blockquote>Hello,
I’m very intrested to ordering and showing categories that have the newest articles only (Category order will change as has newest article). That will make the news more interactive in the categories.
The code is working but I’m also have same error:
Warning: Invalid argument supplied for foreach() in …modules/mod_janews2/helper.php on line 431
( in my file 431 = foreach ( $rows as $cid => $row ) { )So, please could you solve it?</blockquote>
Dear glitter,
I am afraid that it is hard to do as you want,it will need a heavy custom work !
glitter Friendglitter
- Join date:
- March 2010
- Posts:
- 12
- Downloads:
- 0
- Uploads:
- 3
- Thanked:
- 1 times in 1 posts
September 17, 2010 at 4:24 pm #355829I replaced the code:
<blockquote>In helper.php:
FIND:
$query = “SELECT `id`, `title`, `description`, CASE WHEN CHAR_LENGTH(`alias`) THEN CONCAT_WS(“:”, `id`, `alias`) ELSE `id` END as `slug` FROM `#__categories` s WHERE published = 1 and section=” . ( int ) $sid . $where;
$query .= ” ORDER BY s.ordering ASC”; //$query .= ” ORDER BY s.id ASC”;
REPLACE WITH:
$query = “SELECT s.id as id, s.title as title, s.description as description, CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(‘:’, s.id, s.alias) ELSE s.id END as slug FROM jos_content a, jos_categories s WHERE a.catid = s.id AND s.section={$sid} {$where} GROUP BY a.catid ORDER BY MAX(a.created) DESC”;</blockquote>
It’s working, but if user change the setting, the hole section will hidden and the message error will appear again:
Warning: Invalid argument supplied for foreach() in /home/…/public_html/…/modules/mod_janews2/helper.php on line 431
If it’s hard and need a heavy custom work, may it’s good suggestion for new feature in coming ja_news version!
Thanks tienhc & dathq 🙂
glitter Friendglitter
- Join date:
- March 2010
- Posts:
- 12
- Downloads:
- 0
- Uploads:
- 3
- Thanked:
- 1 times in 1 posts
September 18, 2010 at 9:23 pm #355920The problem of foreach() statement occurred if the user try to change the default setting, so may we need two different queries to order the categories:
(1) Default categories order to show categories that have the newest articles.
(2) User categories order to show them as user choices.I tried the following code by if statement. It’s working:
function loadCategories($sid) {
$categories = array ();
$catids = $this->getUserSetting ( $sid, 'categories' );$where = '';
$limit = 0;
if ($catids) {
if (is_array ( $catids ))
$where .= " AND `id` in (" . implode ( ',', $catids ) . ")";
} else {
if (is_array ( $this->getUserSetting ( $sid ) ))
$where = " AND 0";
else
$limit = $this->get( 'max_categories_display' , 3 );
}$db = & JFactory::getDBO ();
if (is_array ( $this->getUserSetting ( $sid ) ) <>3 ) {
$query = "SELECT s.id as id, s.title as title, s.description as description, CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(':', s.id, s.alias) ELSE s.id END as slug FROM jos_content a, jos_categories s WHERE a.catid = s.id AND s.section={$sid} {$where} GROUP BY a.catid ORDER BY MAX(a.created) DESC";
} else {
$query = "SELECT `id`, `title`, `description`, CASE WHEN CHAR_LENGTH(`alias`) THEN CONCAT_WS(":", `id`, `alias`) ELSE `id` END as `slug` FROM `#__categories` s WHERE published = 1 and section=" . ( int ) $sid . $where .' ORDER BY s.ordering';
}$db->setQuery ( $query, 0, $limit );
$rows = $db->loadObjectList ( 'id' );
foreach ( $rows as $cid => $row ) {
$obj = new stdclass ( );
$obj->category = $row;
$categories [] = $obj;
}
return $categories;
}
1 user says Thank You to glitter for this useful post
-
AuthorPosts
This topic contains 15 replies, has 8 voices, and was last updated by pontikoua 13 years, 4 months ago.
We moved to new unified forum. Please post all new support queries in our New Forum