Skip to main content

Joomla facts

Joomla Facts i observed and experienced:

1. To find whether the user is logged in or not in your joomla site.... try this code:

<?php
$user =& JFactory::getUser();
echo '<span style="background-color:#333; color:#ff0000;">ID: '.$user->id.'</span>';
?>

If the user is not logged in, the ID would be generally 0.

 2. Generally to load an article, the following params in the url are sufficient:

index.php?option=com_content&view=article&id=153

But i saw that some modules like search and translate are not displaying in the article page, until we also add the Itemid parameter to the article url.

 ex: &Itemid=157

So the complete article url would be: index.php?option=com_content&id=153&view=article&Itemid=157

3. Below is a sample code to invoke 'login' module in joomla. Try adding this code in your template file.

<?php
jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('login'); // module name
echo JModuleHelper::renderModule($module);
?>

Note: For this to work, the module must be enabled in your admin panel... though it can be assigned at any unused position in your template.

4. A way to identify the home (index) page and other pages in joomla:

<?php
$page_option = JRequest::getVar( 'option', '' );
$pge = $_SERVER['QUERY_STRING'];
if($pge == '' && $page_option == 'com_content')
echo 'home page';
// other way
if(JRequest::getVar('view') == 'frontpage') // index page
?>

5. A way to change the title, meta keywords and descriptions for a page in joomla:
In the file: libraries/joomla/document/html/renderer/head.php, where the page title, keywords and descriptions are rendered, you can change them like the following:

<?php
$page_url = $_SERVER['QUERY_STRING'];
$seo_urls = array('option=com_chronocontact&chronoformname=Feedback&Itemid=159'=>
                            array('title'=>'Give your Feed back',
                            'description'=>'Feedback',
                            'keywords'=>'My website, My pictures, My videos'));
                          
// Generate META tags (needs to happen as early as possible in the head)
        foreach ($document->_metaTags as $type => $tag)
        {
            foreach ($tag as $name => $content)
            {
                if ($type == 'http-equiv') {
                    $strHtml .= $tab.'<meta http-equiv="'.$name.'" content="'.$content.'"'.$tagEnd.$lnEnd;
                } elseif ($type == 'standard') {
                  

                    // meta: title and keywords tags reloaded by shashi
                  
                    if($name == 'title' && array_key_exists($page_url, $seo_urls))
                    $content = $seo_urls[$page_url]['title'];                  
                    else if($name == 'keywords' && array_key_exists($page_url, $seo_urls))
                    $content = $seo_urls[$page_url]['keywords'];
                  
                    $strHtml .= $tab.'<meta name="'.$name.'" content="'.str_replace('"',"'",$content).'"'.$tagEnd.$lnEnd;
                }
            }
        }

        // meta-description tag reloaded by shashi      
        if(array_key_exists($page_url, $seo_urls))
        $page_description = $seo_urls[$page_url]['description'];
        else
        $page_description = $document->getDescription();
      
        $strHtml .= $tab.'<meta name="description" content="'.$page_description.'" />'.$lnEnd;      
      
      
        $strHtml .= $tab.'<meta name="generator" content="'.$document->getGenerator().'" />'.$lnEnd;
      
        // <title> tag reloaded by shashi
        if(array_key_exists($page_url, $seo_urls))
        $page_title = $seo_urls[$page_url]['title'];      
        else
        $page_title = $document->getTitle();
      
        $strHtml .= $tab.'<title>'.htmlspecialchars($page_title).'</title>'.$lnEnd;

        // Generate link declarations
        foreach ($document->_links as $link) {
            $strHtml .= $tab.$link.$tagEnd.$lnEnd;
        }
?>

6. An easy way to define a title, meta tags for title, keywords and description  for a joomla page:

jimport( 'joomla.document.document' );
$doc = & JFactory::getDocument();

$metatitle = 'My Page Title';
$doc->setTitle($metatitle);
$doc->setMetaData( 'title' , $metatitle );
$doc->setMetaData( 'description' , $meta_description );
$doc->setMetaData( 'keywords' , $meta_tags );

7. To view the template positions in the front page of the site, just add the parameter: "tp=1" to the url. Then you can view the different module positions.

8. To load the article or a joomla page, without the default joomla template layout, add the parameter: "&tmpl=component" to the url, or use "index2.php?...." for the url

9. To view the login form of the joomla site, go to:
index.php?option=com_user&view=login

Comments

Popular posts from this blog

Retaining checkbox status of a form after submitting it

we will learn here how to post back or retain the value ( status ) of the checkbox. We will use php header redirection to post back the values to our main page where checkbox is present. We will call form page as first page and action or submitted page as second page. The form data will be received by second page and it is supposed to post back the form data back to form page by using query string through address bar. To keep the second page simple we will keep only the redirection part. Here we have excluded the part which takes care if the form passes its validation and execute the actual script (redirection part). Here is the code of our form with two checkboxes, pb-check.php <?php $t1=$_GET['t1']; $t2=$_GET['t2']; if($t1=="yes"){$t1v="checked";} else{$t1v=="";} if($t2=="yes"){$t2v="checked";} else{$t2v=="";} ?> HTML Form code: <form method="post" action="pb-chk.php"> <inp...

Identify the user's browser

Sometimes there arises a need to identify the user's browser. It is pretty easy to find browser with jquery. So if you have included jquery in your page, it takes a simple line to identify the browser:  if ($. browser . msie ) {} // IE if (($.browser.msie) && ($.browser.version == '6.0')) {} // IE6 if ($. browser . opera ) {} // opera if ($. browser . mozilla) {} // Firefox With the help of php, you can get the browser  details with the help of:  $_SERVER['HTTP_USER_AGENT']; Or you can even use the combined version of php and javascript. php + javascript code: <script type="text/javascript"> var string1 = "<?php echo $_SERVER['HTTP_USER_AGENT']; ?>"; // Browser string var myRegExp1 = /Firefox/; var matchPos1 = string1.search(myRegExp1); var myRegExp2 = /Chrome/; var matchPos2 = string1.search(myRegExp2); var myRegExp3 = /MSIE/; var matchPos3 = string1.search(myRegExp3); if(matchPos1 != -1) ...

Facebook connect using graph api

An example of using facebook graph api to authenticate users: Setup a new application in facebook apps and get the app id and secret. Now follow the steps: Remember to give the same url in the below code, as that of the app settings. <?php if( !isset($_GET['code'])) { ?> <a href="https://graph.facebook.com/oauth/authorize?client_id=xxxxxxxx&redirect_uri=http://xxxxxxxxxxxxxxxx/">Connect using Facebook</a> <?php } $code = trim($_GET['code']); if(isset($_GET['code'])) $token = file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=xxxxxxxx&redirect_uri=http://xxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxx&code=$code"); $token = explode("=", $token); if(isset($_GET['code'])) $user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token='.$token[1]));  print_r($user); ?>