For SEO purposes duplicate page titles is a headache the following hack will solve the problem.
open the file:
components\com_resource\views\list\tmpl\default.php
in line 50 add the following code:
/*START: Page title override */
$doc =& JFactory::getDocument();
$meta_description = $doc->getMetaData("description");
$meta_keywords = $doc->getMetaData("keywords");
$Unique_page_title = $doc->getTitle()." ".$pages;
$Unique_page_description = $meta_description." - ".$pages;
$Unique_page_keywords = $meta_keywords.",".$pages;
$doc->setTitle($Unique_page_title);
$doc->setMetaData( 'description', $Unique_page_description );
$doc->setMetaData( 'keywords', $Unique_page_keywords );
/*END: Page title override */
the above code will generate unique page titles, description and keywords to your article list pages. example "Category Name Page 1 of 10".
Now search engines can index your article listing by page.
Note you can customize the code above by modifying the $Unique_page_title variable.
Enjoy!
Showing posts with label Joomla Codes. Show all posts
Showing posts with label Joomla Codes. Show all posts
Thursday, October 21, 2010
Changing page titles in joomla using the API
Using API15:JDocument/setTitle
Initialize Joomla Page Document Variable
$doc =& JFactory::getDocument();
then use the code below
$doc->setTitle("Your page title here");
Notes:
API15:JDocument/setTitle - Sets the title of the document
Syntax:
setTitle($title)
Initialize Joomla Page Document Variable
$doc =& JFactory::getDocument();
then use the code below
$doc->setTitle("Your page title here");
Notes:
API15:JDocument/setTitle - Sets the title of the document
Syntax:
setTitle($title)
| Parameter Name | Default Value | Description |
|---|---|---|
| $title | $title public |
Monday, October 18, 2010
Joomla Snippet - Strict valid You Tube movies in your articles
If you want to put movies in your articles on a site with a strict doctype you will run into problems with the embed tag that is used by the default code YouTube gives you for example. Embed is actually not XHTML strict valid and this is because embed has been deprecated from XHTML 1.0.
Joomla Snippet - layout switching
Here's some code you can use in your template index file to switch between different layouts based on the menu tree -> menu item ID. You can do all kinds of funky stuff with this.
Using JPane and laoding templates from within a template
Well, let us assume our template is called form.php. My template holds this code to create a pane and to display some content in the pane:
<?php
jimport('joomla.html.pane');
/* creating the pane */
$pane =& JPane::getInstance('tabs'); // change "tabs" to "sliders" or other way round to get the different behaviour
/* creating a content area */
echo $pane->startPane("somecontent-area");
echo $pane->startPanel("panel-name-one","panel1_id");
echo $this->loadTemplate("some-content");
echo $pane->endPanel();
echo $pane->startPanel("panel-name-two","panel2_id");
echo "some content for panel two";
echo $pane->endPanel();
echo $pane->endPane();
?>
The "difficult" thing to remember is, if you want to load a template from within a template... your template to be loaded has to be named like "your-current-template"_"template-to-be-loaded.php"
e.g.
<?php
jimport('joomla.html.pane');
/* creating the pane */
$pane =& JPane::getInstance('tabs'); // change "tabs" to "sliders" or other way round to get the different behaviour
/* creating a content area */
echo $pane->startPane("somecontent-area");
echo $pane->startPanel("panel-name-one","panel1_id");
echo $this->loadTemplate("some-content");
echo $pane->endPanel();
echo $pane->startPanel("panel-name-two","panel2_id");
echo "some content for panel two";
echo $pane->endPanel();
echo $pane->endPane();
?>
The "difficult" thing to remember is, if you want to load a template from within a template... your template to be loaded has to be named like "your-current-template"_"template-to-be-loaded.php"
e.g.
Saturday, October 16, 2010
Friday, October 15, 2010
Tip - How to reuse Joomla 1.0 Templates
Do you have a huge collection of nice Jomla 1.0 templates, and dunno what to do with them? Let's go green and reuse them
Most of templates are easy to adapt. If you don't want to add there new trickery, just want to made them usable in the new environment, jou can do it in a fast and easy way. You need to change only few lines of code in your favourite Joomla 1.0.x templates to make it compatible with Joomla 1.5.*:
Most of templates are easy to adapt. If you don't want to add there new trickery, just want to made them usable in the new environment, jou can do it in a fast and easy way. You need to change only few lines of code in your favourite Joomla 1.0.x templates to make it compatible with Joomla 1.5.*: - <?php mosShowHead(); ?> changed to <jdoc:include type="head" />
- <?php echo $mosConfig_live_site;?> changed to $this->template
- <?php mosLoadModules ( 'user3', -1); ?> changed to <jdoc:include type="modules" name="user3" style="raw" />
- <?php mosMainBody(); ?> changed to <jdoc:include type="component" />
How to disable ?tp=1 in Joomla
2 ways to disable ?tp=1 in joomla:
1. Using the .htaccess file
2. By a core hack
1. Using the .htaccess file
The first and easy method is using the .htraccess file. Most of you may have known that there is a file called htaccess.txt is in your Joomla root. Rename it to the .htaccess and open in favorite text editor .Add the following code :
1. Using the .htaccess file
2. By a core hack
1. Using the .htaccess file
The first and easy method is using the .htraccess file. Most of you may have known that there is a file called htaccess.txt is in your Joomla root. Rename it to the .htaccess and open in favorite text editor .Add the following code :
##### Start ?tp=1 prevention ######
RewriteCond %{QUERY_STRING} tp=(.*)
RewriteRule ^(.*)$ index.php [F,L]
##### End ?tp=1 prevention ###### Please note that not every hosting is not supporting .htaceess and there is a chance that your site may goes down after incluiding this and also this trick will not work for all cases.Thursday, October 14, 2010
Joomla Add External CSS / Style
JDocument/addStyleSheet
Syntax
void addStyleSheet( $url, $type, $media, $attribs )where:
| Argument | Data type | Description | Default |
|---|---|---|---|
| $url | string | URL of stylesheet. | |
| $type | string | MIME type of script. | 'text/css' |
| $media | string | Media type that the stylesheet applies to. | null |
| $attribs | array | Array of attributes. |
Example 1
To add a link to some style sheet at a specific URL, you could use:$doc =& JFactory::getDocument();
$doc->addStyleSheet( 'http://www.example.com/css/mystylesheet.css' );
<link rel="stylesheet" href="http://www.example.com/css/mystylesheet.css" type="text/css" />
Example 2
From a template, you can add a link to a style sheet using a relative URL, like this:$this->addStyleSheet( 'templates/' . $this->template . '/css/mystylesheet.css' );
$this object will be an object of type JDocumentHTML when called from within a template.Joomla Add Style Decleration
Adds an internal stylesheet to the document object. The stylesheet is appended to the document objects' internal stylesheet buffer for the specified type.
where:
Syntax
void addStyleDeclaration( $content, $type )where:
| Argument | Data type | Description | Default |
|---|---|---|---|
| $content | string | Stylesheet content. | |
| $type | string | MIME type of stylesheet. | 'text/css' |
Example
To add a CSS style to the document, you could use:$doc =& JFactory::getDocument();
$style = 'BODY {'
. 'background: #00ff00;'
. 'color: rgb(0,0,255);'
. '}';
$doc->addStyleDeclaration( $style );
source: http://docs.joomla.org/JDocument/addStyleDeclaration
Require Approval For Joomla Web Link
In Joomla! 1.5.3
Change line 105 of components/com_weblinks/views/weblink/view.html.php
from $weblink->approved = 1;
to $weblink->approved = 0;
To remove the published option from the web links form:
comment out lines 59 - 68 of components/com_weblinks/views/weblink/tmpl/form.php
change from
Change line 105 of components/com_weblinks/views/weblink/view.html.php
from $weblink->approved = 1;
to $weblink->approved = 0;
To remove the published option from the web links form:
comment out lines 59 - 68 of components/com_weblinks/views/weblink/tmpl/form.php
change from
to
source: http://docs.joomla.org/Require_Approval_For_Web_Link
Custom error pages in joomla
Joomla! uses the templates/system/error.php file to handle several HTTP Status errors, including "403 Forbidden", "404 Not Found", and "500 Internal Server" errors. You can style the error results, if desired.
It is important to understand that error.php is an independent file from Joomla!. Plugins do not run on the file. You cannot include modules or use <jdoc:include> statements.
If it finds one, Joomla! will use the error.php file from the current template, in place of the system file.
You can format the page, as desired, to match your template.
Next, update your templates/<template-name>/error.php file to reference the new location of the stylesheet by changing this line, accordingly:
Then, simply change the error.css, as desired, for your styling requirements.
Here is an example of how to trap a 404 error and provide a custom message.
If you want Joomla! to return a status code for the error, you can do so by adding logic before the DOCTYPE line, as follows:
First, put the following code in templates/<template-name>/error.php:
Then make the following edits to templates/<template-name>/index.php::
1. Find the following code in index.php
and replace it with the following
2. Find the following code in index.php
and replace it with the following
Now your theme template is applied to error pages too.
Note: Module includes in template will not work on error page created by this method (but will work on other pages).
source: http://docs.joomla.org/Custom_error_pages
Overriding the System Error Results
To override the system error results, copy the templates/system/error.php file into your templates/<template-name> directory.If it finds one, Joomla! will use the error.php file from the current template, in place of the system file.
You can format the page, as desired, to match your template.
Overriding the System Styling
If you want to change the styling, copy the templates/system/css/error.css file into your templates/<template-name>/css directory.Next, update your templates/<template-name>/error.php file to reference the new location of the stylesheet by changing this line, accordingly:
<link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/system/css/error.css" type="text/css" />
Customizing Error Messages
You can add conditional logic to vary the message returned, dependent upon the specific error code.Here is an example of how to trap a 404 error and provide a custom message.
<?php if ($this->error->code == '404') { ?>
<div id="errorboxheader">Page not found</div>
<div id="errorboxbody"><p>Sorry! That page cannot be found.</p>
</div>
</div>
<?php } ?>
HTTP Status Code
When a request is made for a page on your site, the server returns an HTTP status code in response to the request. Joomla! returns a '200 - the server successfully returned the page' for error pages. This is problematic for those working with Google Webmaster Services and trying to get a sitemap resolved.If you want Joomla! to return a status code for the error, you can do so by adding logic before the DOCTYPE line, as follows:
<?php
if ($this->error->code == '404') {
header("HTTP/1.0 404 Not Found");
} ?>
More HTTP Status Code Information
- Joomla! Documentation: Create a Custom 404 Error Page
- HTTP/1.1 Status Code Definitions
- Google Webmaster - Analyzing Crawl Errors
Using Theme Header and Footer on Standard Error Page
If you want to see the error page in theme design and don't like redirecting to error page URL or duplicating HTML in the error page template, here is a way to apply your theme template to the error page.First, put the following code in templates/<template-name>/error.php:
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
include dirname(__FILE__) . "/index.php";
?>
1. Find the following code in index.php
<jdoc:include type="head" />
<?php if (!$this->error->code) : ?>
<jdoc:include type="head" />
<?php else : ?>
<title><?php echo $this->error->code ?> - <?php echo $this->title; ?></title>
<?php endif; ?>
<jdoc:include type="component" />
<?php if ($this->error->code) : /* check if we are on error page, if yes - display error message */ ?>
<p><strong><?php echo $this->error->code ?> - <?php echo $this->error->message ?></strong></p>
<p><strong><?php echo JText::_('You may not be able to visit this page because of:'); ?></strong></p>
<ol>
<li><?php echo JText::_('An out-of-date bookmark/favourite'); ?></li>
<li><?php echo JText::_('A search engine that has an out-of-date listing for this site'); ?></li>
<li><?php echo JText::_('A mis-typed address'); ?></li>
<li><?php echo JText::_('You have no access to this page'); ?></li>
<li><?php echo JText::_('The requested resource was not found'); ?></li>
<li><?php echo JText::_('An error has occurred while processing your request.'); ?></li>
</ol>
<p><strong><?php echo JText::_('Please try one of the following pages:'); ?></strong></p>
<p>
<ul>
<li><a href="<?php echo $this->baseurl; ?>/index.php" title="<?php echo JText::_('Go to the home page'); ?>"><?php echo JText::_('Home Page'); ?></a></li>
</ul>
</p>
<p><?php echo JText::_('If difficulties persist, please contact the system administrator of this site.'); ?></p>
<?php else : ?>
<jdoc:include type="component" />
<?php endif; ?>
Note: Module includes in template will not work on error page created by this method (but will work on other pages).
source: http://docs.joomla.org/Custom_error_pages
How to send email from components - Joomla
How to send email from components
From Joomla! Documentation
This is an example of how to send an email from a component. You would typically put this into your components controller.Fetch the mail object
A reference to the global mail object (JMail) is fetched through the JFactory object. This is the object creating our mail.$mailer =& JFactory::getMailer();
Set a sender
The sender of an email is set with setSender. The function takes an array with an email address and a name as an argument. We fetch the sites email address and name from the global configuration. These are set in the administration back-end (Global Configuration -> Server -> Mail Settings).$config =& JFactory::getConfig();
$sender = array(
$config->getValue( 'config.mailfrom' ),
$config->getValue( 'config.fromname' ) );
$mailer->setSender($sender);
Recipient
You set the recipient of an email with the function addRecipient. To set the email address to the currently logged in user, we fetch it from the user object.$user =& JFactory::getUser();
$recipient = $user->email;
$mailer->addRecipient($recipient);
$recipient = array( 'person1@domain.com', 'person2@domain.com', 'person3@domain.com' );
$mailer->addRecipient($recipient);
Create the mail
We need to set a subject line and create the text body. The subject is set with setSubject.The easy way to create an email body is as a string with plain text. Use the function setBody to add a message to the mail body. You can also attach a file with addAttachment. It takes a single file name or an array of file names as argument.
$body = "Your body string\nin double quotes if you want to parse the \nnewlines etc";
$mailer->setSubject('Your subject string');
$mailer->setBody($body);
// Optional file attached
$mailer->addAttachment(JPATH_COMPONENT.DS.'assets'.DS.'document.pdf');
$body = '<h2>Our mail</h2>'
. '<div>A message to our dear readers'
. '<img src="cid:logo_id" alt="logo"/></div>';
$mailer->isHTML(true);
$mailer->setBody($body);
// Optionally add embedded image
$mailer->AddEmbeddedImage( JPATH_COMPONENT.DS.'assets'.DS.'logo128.jpg', 'logo_id', 'logo.jpg', 'base64', 'image/jpeg' );
Sending the mail
The mail is sent with the function Send. It returns true on success or a JError object.$send =& $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ' . $send->message;
} else {
echo 'Mail sent';
}
The JMail object is used for sending mail in Joomlas contact manager. See the file joomla/components/com_contact/controller.php
Wednesday, October 13, 2010
Adding meta data manually by codes in joomla
JDocument/setMetaData
From Joomla! Documentation
Jump to: navigation, search
Sets the value of a meta data item.
where:
| Argument | Data type | Description | Default |
|---|---|---|---|
| $name | string | Name of meta data item. If $name is 'description' or 'generator' then the effect is the same as calling setDescription or setGenerator respectively. Meta data names are always folded to lowercase. | |
| $content | string | Content of meta data item. If there is already a meta data item with the same value of $name (case independent) then this value will replace it. | |
| $http-equiv | Boolean | True if meta data item is equivalent to an HTTP header field. | false |
Example 1
$doc =& JFactory::getDocument();
$doc->setMetaData( 'tag-name', 'tag-content' );
<meta name="tag-name" content="tag-content" />
Example 2
$doc =& JFactory::getDocument();
$doc->setMetaData( 'tag-name', 'tag-content', true );
<meta http-equiv="tag-name" content="tag-content" />
See also
Retrieved from "http://docs.joomla.org/JDocument/setMetaData"
Exclude Categories in Joomla Search Results
Problem deteced: Using the Joomla 1.5.7 native search engine, there is no posibility to avoid some categories of been included on the serch.
Before copying UPDATING files, backup the original files!!!!!!!!!!
THE USE OF THIS UPGRADE IS AT YOUR OWN RESPONSABILITY
Files modified:
joomladir\plugins\search\content.php
joomladir\plugins\search\content.xml
After copying those files go to Section Extensions -> Plugin Manager -> Search Content
You'll see the new parameter to exclude categories
https://sites.google.com/site/myblogfileattachments/home/Files/joomla_1.5.20_and_joomfish_exclude_from_search.zip
source: http://forum.joomla.org/viewtopic.php?p=2239288
Before copying UPDATING files, backup the original files!!!!!!!!!!
THE USE OF THIS UPGRADE IS AT YOUR OWN RESPONSABILITY
Files modified:
joomladir\plugins\search\content.php
joomladir\plugins\search\content.xml
After copying those files go to Section Extensions -> Plugin Manager -> Search Content
You'll see the new parameter to exclude categories
https://sites.google.com/site/myblogfileattachments/home/Files/joomla_1.5.20_and_joomfish_exclude_from_search.zip
source: http://forum.joomla.org/viewtopic.php?p=2239288
Increasing Number of Characters in Search Box in joomla
1. changed line 62-65 in administrator/components/com_search/helpers/search.php:
Code:
// limit searchword to 20 characters
if ( JString::strlen( $searchword ) > 50 ) {
$searchword = JString::substr( $searchword, 0, 49 );
$restriction = true;
if ( JString::strlen( $searchword ) > 50 ) {
$searchword = JString::substr( $searchword, 0, 49 );
$restriction = true;
Removing the Joomla Generator Tag
A common request from Joomla web masters is the ability to remove the generator meta tag from the source output of the site. This is usually for security reasons to make it less obvious that the site is running Joomla. The generator value is really easy to modify and remove with one line of PHP code.
Fire up your favourite editor and load the
There are several other files that could be loaded by Joomla in the template. You will also need to do this to the
This is just another example of how flexible the Joomla templating engine is and why it's a makes Joomla a great choice to power your web site ... anonymously.
source: http://www.theartofjoomla.com/home/19-designer/64-removing-the-joomla-generator-tag.html
Fire up your favourite editor and load the
index.php file of the default template on your site. Most templates should have a block of PHP at the top of the file starting with <?php and closing with ?>. Find this block and just before the closing PHP brace, insert the following lines of code:// Remove the generator meta tagWhat we have done here is told the template (that's what
$this->setGenerator(null);
?>
$this is) to set the value of the meta generator tag (that's what setGenerator does) to nothing (that's what null means). When you do this, refresh your web page and view the source of the output. Scan down from the top of the file to find the meta generator tag.<meta name="generator" content="" />You can see it's obviously still there but the value is empty, giving you no clues as to what CMS is running the web site. Nothing is probably the safest value, but you could set it to anything you like if you really wanted to.
There are several other files that could be loaded by Joomla in the template. You will also need to do this to the
component.php (that supports the Joomla Print View) and if you have a custom Error or Offline page, you will need to add the line of code to error.php and offline.php respectively. You can find out more about these additional template files in the Template section of the Art of Joomla Developer Reference.This is just another example of how flexible the Joomla templating engine is and why it's a makes Joomla a great choice to power your web site ... anonymously.
source: http://www.theartofjoomla.com/home/19-designer/64-removing-the-joomla-generator-tag.html
Adding External Javascript in joomla
JDocument/addScript
Adds the definition of a linked external script to the document object. Duplicates are ignored.Syntax
void addScript( $url, $type )where:
| Argument | Data type | Description | Default |
|---|---|---|---|
| $url | string | URL of script. | |
| $type | string | MIME type of script. | 'text/javascript' |
Example
To add a link to some JavaScript code at a specific URL, you could use:$doc =& JFactory::getDocument();
$doc->addScript("http://www.example.com/js/myscript.js");
produce following link in the HTML HEAD section:
<script type="text/javascript" src="http://www.example.com/js/myscript.js"></script>
source: http://docs.joomla.org/JDocument/addScriptDeclaration
Adding script Decleration in joomla
Adds an internal script to the document object. The script is appended to the document objects' internal script buffer for the specified type.
source:
http://docs.joomla.org/JDocument/addScriptDeclaration
Syntax
void addScriptDeclaration( $content, $type )| Argument | Data type | Description | Default |
|---|---|---|---|
| $content | string | Script content. | |
| $type | string | MIME type of script. | 'text/javascript' |
Example 1
To add a Hello World alert in JavaScript, you could use:$content = 'alert( \'Hello Joomla!\' )';
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration( $content );
Example 2
Adding a slightly more realistic piece of JavaScript:function getJavaScript($message) {
$javascript .= 'if(window.addEventListener){ // Mozilla, Netscape, Firefox' . "\n";
$javascript .= ' window.addEventListener("load", function(){ alert("' . $message . '");}, false);' . "\n";
$javascript .= '} else { // IE' . "\n";
$javascript .= ' window.attachEvent("onload", function(){ alert("' . $message . '");});' . "\n";
$javascript .= '}';
return $javascript;
}
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration( getJavaScript( 'This will appear in an alert box after the page loads.' ) );
source:
http://docs.joomla.org/JDocument/addScriptDeclaration
Tuesday, October 12, 2010
Joomla as a PHP Framework
Sample Codes:
<?php
/* Initialize Joomla framework */
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
/* Required Files */
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/* To use Joomla's Database Class */
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
/**************************************************/
// Your code starts here...
/**************************************************/
?>
<?php
/* Initialize Joomla framework */
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
/* Required Files */
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/* To use Joomla's Database Class */
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
/**************************************************/
// Your code starts here...
/**************************************************/
?>
Subscribe to:
Posts (Atom)

