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

php strip all tags

The below function can strip almost all tags from a string. function strip_all_tags($string) {     $string = preg_replace( '@<(script|style)[^>]*?>.*?@si', '', $string );     $string = strip_tags($string);     return trim($string); } $a = '<script type="text/javascript" src="jquery.js"></script> <div id="test" style="padding:5px; color:red;">Hello world</div>'; echo strip_all_tags($a); // outputs: Hello world

htaccess disable directory browsing, disable file listing, disable file access

There may be some personal or secure data in a file, that you want to hide from the end user, when it is viewed through a web browser. Ex: http://www.example.com/user_files/24/chat.txt In the above scenario, if the file "chat.txt" contains a secure data, and you dont want to allow end users to directly access the file, or to disable the file listing in the folder "user_files" or "24", use the below code in your .htaccess file inside "user_files" folder: Options -Indexes order allow,deny deny from all

css link remove dotted outline

Its quite awkward to look at the link, when it is clicked and the dotted outline appears on it. To overcome it, just add the following line to your css file: a { outline: 0; } For example, to remove the dotted outline for the menu links on your page, add this to your css: #navigation li a {    outline: 0; } ( Assuming you have this menu structure: <ul id="navigation"><li><a href="news.html">News</a></li></ul> )