Web Design
Search Engine Optimization
VIETSEO COMPUTING AND SERVICES CO., LTD

HO CHI MINH:
* Room 3B05-3B06, Indochina Park Tower, 04 Nguyen Dinh Chieu Street, Da Kao Ward, District 1, HCMC, Vietnam
* (4th Floor) 143-145 Phan Long, Ward 7, Phu Nhuan District, HCM City
* Tel: (08) 2239 8757 - (08) 223 77147
* Mobile: 0917 212 969 - English Language: 0918 117 145
* Fax: (08) 2220 08 23

BINH DUONG:
* No 299/11, Tan Dinh Village, Ben Cat District, Binh Duong Province
* Tel: (06503) 511 072
* Mobile: 0917 212 969 - English Language: 0918 117 145
* Fax: (06503) 511 072

HA NOI:
* Room 401, Vinaasset Tower, 7 Lane 45/10 Nguyen Hong, Dong Da, Ha Noi
* Mobile: 0917 212 969

* Email: vietseo @ vietseo.com

Sales:
VietSEO

Support Online:
VietSEO

Skype Chat:
Skype Chat

Search:

The Web Vietseo.com

News Categories:
SEO - Web - Internet
Website Introduction
IT Of Vietnam News
IT Internation News
Business - Businessman
Hardware - Device
Software - OS
Downloads
Virus-Hacker
Knowledge Basic
Observe
Telephone - Mobile
Entertainment - Others
Web Design
Web DesignHome Page Search Engine OptimizationNews Web DesignSEO - Web - Internet

How to Display Your Page Title in Your Template - Joomla! 1.5

Updated At: 11:41 AM, 09/16/2011  How to Display Your Page Title in Your Template - Joomla! 1.5

Page Titles in Joomla! 1.5

If you've already worked with Joomla! 1.5, you know that page titles are handled differently than in version 1.0. In version 1.0, if you enabled dynamic page titles (see this article for an explanation), each page would have an html title of "Site Name - Page Title". For example, the HTML title of this page is "Cory Webb's How to Joomla! - How to Display Your Page Title in Your Template - Joomla! 1.5", where "Cory Webb's How To Joomla!" is the site name, and "How to Display Your Page Title in Your Template - Joomla! 1.5" is the page title.

In Joomla! 1.5, dynamic page titles are used by default, and the site name is not displayed in the html title. For example, if this site were running in Joomla! 1.5, you could look up in the browser's window header and see that the html title just said "How to Display Your Page Title in Your Template - Joomla! 1.5". That makes things a bit easier in terms of getting access to the page title, but it causes another problem; your site name is not part of the html title. There is an SEF Patch that enables you to modify the HTML title, but I will show you a trick for doing this in your template. Think of this as 2 how-to's in 1.

Accessing Your Page Title from Your Template

There are 2 objects in Joomla! 1.5 that are extremely powerful and extremely useful for doing some advanced tricks in your template. The first object is JFactory, which is basically the gateway for accessing just about anything in the Joomla! API, and the second is JDocument, which gives you access to your document's properties. Your document is usually defined as the HTML output from Joomla!, but it could also be a PDF, XML/RSS, or raw output/text. In this case, we are only concerned with the HTML output.

To access your page title, simply add the following code to the top of your template "index.php" file:

 
<?php
 
$mydoc =& JFactory::getDocument();
$mytitle = $mydoc->getTitle();
 
?>
 

That's it. That's all there is to it. Pretty simple, huh? Now, to display your page title within your template, you simply add the following code anywhere in your template "index.php" file that you wish to display the page title:

 
<?php echo $mytitle; ?>
 

That's all there is to it. Pretty easy.

Modifying Your HTML Title

The next thing we want to do is modify your html title. We will be using the JDocument object that we just accessed. Using this code, you can set the html title of your page:

 
$conf =& JFactory::getConfig();
$sitename = $conf->getValue('config.sitename');
 
$mydoc->setTitle($mytitle.' - '.$sitename);
 

Notice that I used JFactory again to get a copy of the Joomla! configuration, which I then used to get the value of the site name (config.sitename). Then, I used "$mydoc" from the earlier step to set the html title.

Note that this code sets the html title to "Page Title - Site Name". If you want to set it to "Site Name - Page Title", you need to change the setTitle parameter to "$sitename.' - '.$mytitle". In reality, you can set the html title to anything you want, but I personally think "Page Title - Site Name" makes the most sense.

Putting it All Together

Using the following code, you are simultaneously getting dynamic access to your page title and setting the value of your html title:

 
<?php
 
$mydoc =& JFactory::getDocument();
$mytitle = $mydoc->getTitle();
 
$conf =& JFactory::getConfig();
$sitename = $conf->getValue('config.sitename');
 
$mydoc->setTitle($mytitle.' - '.$sitename);
 
?>
 
Việt SEO | Trở Về   Đầu Trang
Web DesignOlder Post
Website DesignRanking SEO Knowledge: Basic, Intermediate, Advanced
Website DesignEnhance computer security, guard against virus, hacker,...
Website DesignWinGate
Website DesignMicrosoft's plans for post-Windows OS revealed
Website DesignIntel to launch Linux-powered mobile Internet device
Website DesignGoogle tops profit target, stock jumps
Website DesignWebsite on Vietnam launched
Website DesignMobifone, Yahoo offer search engine for mobile users
Website DesignGoogle testing Intel SSDs
Website DesignSun to clarify JavaFX open-source plan later this year

Công tyXe hyundaiDịch vụ thám tửBán blackberryCho thuê xeViet NamVăn phòng phẩmThám tửÔ tôOffice for leaseVietnam travelQuảng bá websiteBlackberryLaptop xách tayMáy tính xách tayMáy chấm côngCho thuê xeThiết kế quảng cáoVietnam virtual officeNha khoaTư vấn luậtStainless steel productsDiệt chuộtThị trường Chứng khoánNước hoaBếp gasLaptop hpMáy bắn cátDu lichBlackberryDanh ba doanh nghiepSan goTham tu Sai GonCho thue xeVăn phòng ảoQuảng cáo trực tuyếnCho thuê ô tôMay tinh xach tayĐiện thoại blackberryBat dong sanOto HyundaiLaptop dell
Web Design
OUR SERVICES
Web Design
* Search Engine Optimization (SEO)
* Website Design
* Google Adwords
OTHERS
Web Directory
Web Templates
NEWS
News
SEO - Web - Internet Website Introduction
IT Of Vietnam News IT Internation News
Business - Businessman Hardware - Device
Software - OS Downloads
Virus-Hacker Knowledge Basic
Observe Telephone - Mobile
Entertainment - Others