Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » post module if no article present
post module if no article present
Re: post module if no article present
Sure, that shouldn't be too hard. We'll just modify one of the "Article" recipes on http://www.metamodpro.com/support/recip … e-category
Code:
if ( $option == "com_content" and $view == "category" ) {
/* category list pages (blog or list style) */
$category_id = (int)$id;
$nullDate = $db->Quote( $db->getNullDate() );
$my_id = $db->Quote( $db->getEscaped( (int)$id ) );
$jnow =& JFactory::getDate();
$now = $db->Quote( $db->getEscaped( $jnow->toMySQL() ) );
$query = "SELECT count(*) as c"
. " FROM #__content WHERE catid = $category_id AND state = 1"
. " AND ( publish_up = $nullDate "
. " OR publish_up <= $now )"
. " AND ( publish_down = $nullDate "
. " OR publish_down >= $now )";
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$count = (int)@$row->c;
if ($count == 0) return XXX; // module id to display when there are no items in this category
}
Tested, and works nicely on my test server.
Cheers,
Stephen
Re: post module if no article present
Thanks for this Stephen, your a legend.
Can I trouble you for a slight modification. Is there a way to modify the code so that a module is displayed only when the count of articles that are NOT labelled Frontpage (Joomla article manager) is 0. Currently the module counts all articles Frontpage or not. Could it be more specific. Thanks in advance.
Re: post module if no article present
I think so - try this:
Code:
if ( $option == "com_content" and $view == "category" ) {
/* category list pages (blog or list style) */
$category_id = (int)$id;
$nullDate = $db->Quote( $db->getNullDate() );
$my_id = $db->Quote( $db->getEscaped( (int)$id ) );
$jnow =& JFactory::getDate();
$now = $db->Quote( $db->getEscaped( $jnow->toMySQL() ) );
$query = "SELECT count(*) as c"
. " FROM #__content WHERE catid = $category_id AND state = 1"
. " AND id not in (select content_id from #__content_frontpage) "
. " AND ( publish_up = $nullDate "
. " OR publish_up <= $now )"
. " AND ( publish_down = $nullDate "
. " OR publish_down >= $now )";
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$count = (int)@$row->c;
if ($count == 0) return XXX; // module id to display when there are no items in this category
}
Re: post module if no article present
Hi
This looks very interesting! I have News Show Pro GK5 on my front page. But I get a 1064 error if no article in a specific category is published. So I am trying to display a module if there is no articles published in that category. How can I specify a category and display News Show Pro GK5 if articles are published and a another module if no articles are published? (if else).
Code:
if ( $option == "com_content" and $view == "article" and $id == '19' ) {
/* category list pages (blog or list style) */
$category_id = (int)$id;
$nullDate = $db->Quote( $db->getNullDate() );
$my_id = $db->Quote( $db->getEscaped( (int)$id ) );
$jnow =& JFactory::getDate();
$now = $db->Quote( $db->getEscaped( $jnow->toMySQL() ) );
$query = "SELECT count(*) as c"
. " FROM jos_content WHERE catid = $category_id AND state = 1"
. " AND id not in (select content_id from jos_content_frontpage) "
. " AND ( publish_up = $nullDate "
. " OR publish_up <= $now )"
. " AND ( publish_down = $nullDate "
. " OR publish_down >= $now )";
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$count = (int)@$row->c;
if ($count == 0) return 130; // module id to display when there are no items in a specific category
}
Thanks in advance
Jon
Re: post module if no article present
Hi Jon,
can you tell me what version of Joomla you are using? The PHP and SQL query may be a little different in each case.
If you simply want to alter the code above to be an if/else, then change that 2nd-to-last line (with the "if" in it) to this:
if ($count == 0) return 130; // when no items in category
else return 131; // when there are items in category
Thanks,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » post module if no article present
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Posts this week:
- 2
- User Info:
- Total Users:
- 7627
- Newest User:
- rudys68879
- Members Online:
- 0
- Guests Online:
- 198
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked