Some time ago I talked about how to know if you are in the frontpage or not
But you might want to know (for instance, for plugin displaying) if you are viewing a full article or just a listing of articles (with just a preview of the articles’ content).
How do you do this? You must use the JRequest::getVar function as in:
if (JRequest::getVar('view')=='article'){
// then you are displaying a full article
// do whatever you want in full article visualization...
}
else{
// stuff to be displayed in the rest of the pages...
} |
You could also use JRequest::getvar('option', '') or JRequest::getCmd( 'option' )to know if you are, for instance, in com_content or in any other module as in:
<?php if((JRequest::getCmd( 'view' ) == 'article') or (JRequest::getCmd( 'option' ) == 'com_twc4j')) :?> |
With this lines you could hack some plugins (like, for example, addthis plugin for joomla) to display just as you want. Take a look at this self-explained code:
function getButtonCode(&$params) {
if($_REQUEST['view']=="frontpage") return ''; //we are in the frontpage, so return an empty string
if (JRequest::getVar('view')!='article') return ''; //we are not showing an article, so return an empty string
// Here we know that we are displaying an article... so I want to show addthis code.
$code = $this->params->get('code');
if( empty($code) )
$code = '<br/><a href="http://www.addthis.com/bookmark.php?v=250" onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js?pub=xa-4a3f0b283a364b52"></script><br/>';
return $code;
} |
Thanks a lot to shockM user of joomlaspanish.org forums for the explanation! (Read full post in spanish here).
