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

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

php get content between tags

This involves parsing the dom document. <?php function getTextBetweenTags($tag, $html) {     $dom = new domDocument;     @$dom->loadHTML($html);         $dom->preserveWhiteSpace = false;     $content = $dom->getElementsByTagname($tag);     $out = array();         foreach ($content as $item)     {         $out[] = $item->nodeValue;     }     return $out; } $xhtml = '<tag>abc def</tag><tag>123 456</tag>'; $content2 = getTextBetweenTags('tag', $xhtml); foreach( $content2 as $item ) {     echo $item.'<br />'; } ?> Output: abc def 123 456