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
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
Post a Comment