Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » [solved] Just show module title if...
[solved] Just show module title if published article
[solved] Just show module title if published article
I have joomla latest news showing articles from a single category if the article is published, it works fine. But in the case there is no articles published in the category I don't to want show the module title. I have not achieved this, the module title is always shown. It should not be difficult, but I'm far from an expert in coding.
My code is borrowed from this site and slightly modified. I have not found out there to put my "catid".
Code:
$category_id = null;
if ( $option == "com_content" ) {
if ( $view == "category" ) {
/* category list pages (blog or list style) */
$category_id = (int)$id;
} else if (array_key_exists("catid",$_REQUEST)) {
/* if the category id is in the URL */
$category_id = (int)JRequest::getInt("catid",0);
}
if ( $category_id === null && $view == "article" ) {
/* if it's an article page without the catid mentioned in the url */
$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 title, id, catid "
. " FROM jos_content WHERE id = $my_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();
$category_id = $row->catid;
}
}
if ($changes->mod(116)->showTitle(true)) return 116;
else if ($changes->mod(116)->showTitle(false)) return 116;
Regards
Matt
Joomla 2.5.11
MetaMod 3.13b
MetaMod bug: No errors
17-Jun-13 11:29:53
Re: [solved] Just show module title if published article
Hi Matt,
ok, I think I see what you are trying to do here. There are several issues:
1 - you can't use "$changes->mod(116)->showTitle(true)" to detect the current state of the title. It's only used for setting the title status.
2 - all the 1st part of the PHP you posted was about getting hold of the category id of the current page on the site (e.g. the category of the article if it's showing an article, and the category id of the category if it's showing a category). I don't think you need this. As I understand it, you just want to use the category of the *module*, not the category of the page to be the determining factor.
So here's how we are going to approach it:
1 - get the category id used by the module. Unfortunately there's no easy way for MetaMod to get this info, so you'll just have to hard-code it in.
2 - do a database query to find out how many published items are in that category.
3 - if there are none, hide the module title
4 - include the module.
Here's how I would do it:
Code:
$catid = 21; // MODIFY THIS to the category id that you want to check for the module.
$nullDate = $db->Quote($db->getNullDate());
$date = JFactory::getDate();
$nowDate = $db->Quote($date->toSql());
$query = "SELECT count(*) "
. " FROM #_"
. "_content WHERE catid = $catid AND state = 1"
. " AND ( publish_up = $nullDate "
. " OR publish_up <= $nowDate )"
. " AND ( publish_down = $nullDate "
. " OR publish_down >= $nowDate )";
$db->setQuery( $query );
$count = $db->loadResult();
if ($count == 0) {
$changes->mod(116)->showTitle(false);
}
return 116;
Cheers,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » [solved] Just show module title if...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 2
- User Info:
- Total Users:
- 7667
- Newest User:
- humble2601
- Members Online:
- 0
- Guests Online:
- 222
- 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