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...

Joomla validate chrono forms using jquery

It is a common practice to use Chrono forms in our joomla site to setup various forms in the site, be it a contact us form, submit a ticket form, or whatever. I have set the option "validate form" to "No" under chronoform settings in admin panel, and also preferred to not include any js or css files. For validating the chrono forms, i prefer jquery. So first lets add jquery support in our joomla. It is quite simple: 1. Download jquery.js and jquery_min.js (1.4.2 version is enough) and place them in media/system/js folder of your joomla. 2. Edit libraries->joomla->html->html->behavior.php, and add the following function below the mootools() function: function jQuery($debug = null)     {         static $loaded;         global $mainframe;         // Only load once         if ($loaded) {    ...

Mysql join examples

1. Inner join: Sample Fields in "person" table:  id, email, password, firstname, lastname Sample Fields in "personprofile" table: person_id, age, dob, city, country, phone, mobile Query: select * from person inner join `personprofile` on person.id=personprofile.person_id and person.id=9; 2.  Left join: Sample fields in "employee" table: emp_id (primary), name, active Sample fields in "online" table: id (primary), user_id (references emp_id), online Query: SELECT *  FROM employee e left join online o on e.emp_id = o.user_id where e.active=1; Note the use of "where" in the above query, instead of normal "and". It will give the accurate results.