How to Get Page Title in Joomla 1.0.x

Search terms:
How to get the page title in Joomla 1.0.x
How to get the content title in Joomla 1.0.x
How to get the article title in Joomla 1.0.x
How to show the page title in Joomla 1.0.x
How to show the content title in Joomla 1.0.x
How to show the article title in Joomla 1.0.x

After several long hours of trying many methods of obtaining the page title of a content item, I finally stumbled across the solution.

 In my blogs, I wanted to have the pagination and the results of additional blog entries at the bottom of the page (as you can see on this page where it allows you to click next/previous/etc).  If I turned off pagination, the actual title of the content item would appear in the title.  However, if I turn on pagination, it does not do so IF you follow the links using the pagination below.  You can try this yourself – if you click on “next” below, you will see the title of the page at the top of your browser say “BsnTech Networks – BsnTech Blog – Computers” instead of the actual name of the content item.

Why do I want the content item title so bad?  Well, I use a tracker on my site to see what pages visitors are viewing.  If I can’t get the correct title, every Computer blog entry (or any other Blog I have) will show as the very same page – because the actual title never changes!

So I FINALLY found a solution that will allow me to keep the pagination feature on and to log the REAL content item title that each visitor views.

I tried many methods and none worked.  I tried to get the Itemid, id, Contentid, and many other options.  With the pagination feature on, none of the IDs returned were the actual ID of the content item in question – it was some other ID.  I was going to couple this with a database query to pull the title from the content table where the id equaled the page’s ID.  No-Go.

I then tried to use the mosMainBody() feature and store it to a PHP variable – where I would then get the string after the “contentheading” TD Class.  When I tried this, the whole mosMainBody actually appeared on the webpage and this wasn’t succesful either!

So, alas, I have the solution to finally allow you to get your page title in Joomla 1.0.x and store it to a PHP variable.  Here’s the trick:

You need to open up the content.html.php file in the components/com_content directory.  You then need to go down to around line 624 – I cannot tell exactly what line yours may say because I’ve done other tweaking to this file, but the line will look like this:

function Title( &$row,  &$params, &$access ) {

Just under this line, I added the following lines.  The following lines will basically take the page title and store it in a GLOBAL PHP variable called “myTitle”.  It has to be a GLOBAL variable so that it can be accessed in your template.

//below are two lines added to get the page title and store it in myTitle
global $myTitle;
$myTitle = $row->title;

Now, go into your template index.php file and you can use the $myTitle variable anywhere that you want the actual title of the content item to show up.

So now I have the both of best worlds on my blogging sites – I can allow my visitors to use the pagination features at the bottom of the blog pages to follow my blog entries in order, list the blog entries on the right-hand side so visitors can click specifically on an entry that interests them (this was other PHP code I wrote to pull the data from the database and construct the link – which actually does show the correct title in the browser’s title bar), and also see what pages visitors view on my statistics information pages.