HOME TIPS FORUMS DOWNLOADS
   »»  Tips Archive |
Tricks/Tools : Add Your Own Page Titles
Posted by tl001 on 2004/12/21 19:49:06 (4338 reads)
Tricks/Tools

Unless you operate a site like xoops.org, you must pay attention to your search engine ranking in order to generate traffic to your site.

There are many factors in ranking your sites. Some are under your control and some are not. To get a higher ranking, you generally would need more inbound links and contents. In addition to the two factors, page titles also play an important role in the ranking. It is not too complicated to implement page titles.



First you must decide what information you want to display in the title, then read the file and look for how that information is retrieved from your database.

Example: Evennews, message.php
Goal: to display the newsletter subject


<?php
require('header.php');
$dirname = $xoopsModule->dirname();

if (isset($_POST['action']))
	$action = $_POST['action'];
else if (isset($_GET['action']) && !isset($_POST['action']))
	$action = $_GET['action'];
else
	$action = '';

$mess_id = isset($_POST['mess_id']) ? intval($_POST['mess_id']) : 
intval($HTTP_GET_VARS['mess_id']);

if ($action == 'view_mess') {
	$sql    = "SELECT * FROM " . $xoopsDB->prefix("evennews_messages") . 
" WHERE mess_id=$mess_id";
	$arr    = $xoopsDB->fetchArray($xoopsDB->query($sql));

	$xoopsOption['template_main'] = 'evennews_message.html';
	include(XOOPS_ROOT_PATH.'/header.php');	// Include the page header

	$xoopsTpl->assign('lang_date', _EN_TIME);
	$xoopsTpl->assign('lang_from', _EN_FROM);
	$xoopsTpl->assign('lang_subject', _EN_SUBJECT);
	$xoopsTpl->assign('lang_message', _EN_MESSAGE_BODY);

	$xoopsTpl->assign('en_title', sprintf(_EN_VIEW_MESS, $arr['mess_id']));
	$xoopsTpl->assign('en_messagetime',
 formatTimestamp($arr['time_sent'], "D d-M-Y"));
//	$xoopsTpl->assign('en_messagefrom', $arr['mess_from']);
// comment up newsletter admin email address to prevent spamming
	$xoopsTpl->assign('en_messagefrom', 'newsletter admin');
	$xoopsTpl->assign('en_subject', $arr['subject']);
	$xoopsTpl->assign('en_message', $arr['message']);

	// Include the page footer
	include(XOOPS_ROOT_PATH.'/footer.php');
} else {
	redirect_header('archives.php',1,"");
}
?>


Notice that information retrieved from the database is listed in an array
$arr = $xoopsDB->fetchArray($xoopsDB->query($sql));

subject can be trieved as $arr['subject']. Now we can add this into the file and assign pagetitle.


<?php
require('header.php');
$dirname = $xoopsModule->dirname();

if (isset($_POST['action']))
	$action = $_POST['action'];
else if (isset($_GET['action']) && !isset($_POST['action']))
	$action = $_GET['action'];
else
	$action = '';

$mess_id = isset($_POST['mess_id']) ? intval($_POST['mess_id']) : 
intval($HTTP_GET_VARS['mess_id']);

if ($action == 'view_mess') {
	$sql    = "SELECT * FROM " . $xoopsDB->prefix("evennews_messages") . " 
WHERE mess_id=$mess_id";
	$arr    = $xoopsDB->fetchArray($xoopsDB->query($sql));

	$xoopsOption['template_main'] = 'evennews_message.html';
	include(XOOPS_ROOT_PATH.'/header.php');	// Include the page header

	$xoopsTpl->assign('lang_date', _EN_TIME);
	$xoopsTpl->assign('lang_from', _EN_FROM);
	$xoopsTpl->assign('lang_subject', _EN_SUBJECT);
	$xoopsTpl->assign('lang_message', _EN_MESSAGE_BODY);

	$xoopsTpl->assign('en_title', sprintf(_EN_VIEW_MESS, $arr['mess_id']));
	$xoopsTpl->assign('en_messagetime', 
formatTimestamp($arr['time_sent'], "D d-M-Y"));
//	$xoopsTpl->assign('en_messagefrom', $arr['mess_from']);
// comment up newsletter admin email address to prevent spamming
	$xoopsTpl->assign('en_messagefrom', 'newsletter admin');
	$xoopsTpl->assign('en_subject', $arr['subject']);
	$xoopsTpl->assign('en_message', $arr['message']);

	
	$ptitle = $arr['subject'];
 	$xoopsTpl->assign('xoops_pagetitle', $ptitle);
	
	// Include the page footer
	include(XOOPS_ROOT_PATH.'/footer.php');
} else {
	redirect_header('archives.php',1,"");
}
?>


Now we have a page title for each newsletter. Hope this serves an example and could help adding your own page titles. Some of the modules like News use classes to retrieve information from database so you will need look there for clues.

Printer Friendly Page Send this Story to a Friend
The comments are owned by the poster. We aren't responsible for their content.
Poster Thread
tl001
Posted: 2005/6/18 10:58  Updated: 2005/6/18 11:01
Webmaster
Joined: 2004/6/10
From:
Posts: 282
 to Tim, UK - Re: Add Your Own Page Titles
Quote:

Hi i need a little help on your pdf Smarty Uses and on How to add your own page titles to your modules and web pages i dont understand really what i have to do and what i have edit. I have made my own change to <title><{$xoops_sitename}> - <{$story.title}></title> but its not quite right can you help me?

Cheers

Tim


Tim: the contact form is not for answering questions about our TIPs. We would appreciate it if you could register with us and post your comments in the future.

As of your question, this TIP should explain on how you can accomplish it. You first must decide what to be your pagetitle, then assign that to pagetitle smarty variable.

Not sure about your story.title part, if you are using the latest news module, you should not worry about it, as it already has the pagetitle part covered.

Please register and post your further questions.
tgrigg
Posted: 2005/6/19 16:28  Updated: 2005/8/21 20:22
Just popping in
Joined: 2005/6/19
From:
Posts: 1
 Re: Add Your Own Page Titles
Cheers for that now i have read and this is what i have done, I have added this code to news module article.php

Quote:
$ptitle = $story['title'];
$xoopsTpl->assign('xoops_pagetitle', $ptitle);


but it's not worked to good it puts this in the page title

Quote:
<a href='http://192.168.2.4/modules/news/index.php?storytopic=1'>
XOOPS</a>&nbsp;:&nbsp;50p Off PowerPlayDirect Discount Code </a>


Could you help me fix it please
tl001
Posted: 2005/6/19 16:51  Updated: 2005/6/19 16:51
Webmaster
Joined: 2004/6/10
From:
Posts: 282
 Re: Add Your Own Page Titles
Tim:
You need to use article->title
$ptitle=$myts->makeTboxData4Show($article->title());
$xoopsTpl->assign('xoops_pagetitle', $ptitle);

$story['title'] is for the display of news' URLs.

As I have mentioned earlier, you may want to upgrade your news to the most recent version, so you don't have to worry about display of your news titles.

Or take a close look on how the pagetitle is being assigned by the recent versions.
macmend
Posted: 2005/8/21 19:57  Updated: 2005/8/21 20:02
Just popping in
Joined: 2005/8/21
From:
Posts: 17
 Re: Add Your Own Page Titles
I am struggling with weblog 1.41 module, as for the categories and weblog entries the correct code is not obvious, it appears to use some kind of varying string, but as I am only a part time coder I am not sure.

for example

$category['cat_title'] = $cat->getVar('cat_title', 's');

there are no obvious relationships between category or article title and simple dollar encode words like $cat or $cat_id, these all seem to be arrays or display as the word array.....eek...help
tl001
Posted: 2005/8/21 20:17  Updated: 2005/8/21 20:21
Webmaster
Joined: 2004/6/10
From:
Posts: 282
 Re: Add Your Own Page Titles
I don't use weblog, I have just downloaded it and taken a look.

The module has assigned a title which you can "borrow" as a pagetitle
Quote:

$xoopsTpl->assign('title', $entryObject->getVar('title'));


try to add one line after it
Quote:

$xoopsTpl->assign('title', $entryObject->getVar('title'));
$xoopsTpl->assign('xoops_pagetitle', $entryObject->getVar('title'));


If you want to add categories into pagatitle, use the following:
Quote:

$xoopsTpl->assign('xoops_pagetitle',
htmlentities($entryObject->getVar('title') .
' -' . $entryObject->getVar('cat_id') ));


You may want to take a closer look of News module to see how it assigns pagetitle.
macmend
Posted: 2005/8/22 4:15  Updated: 2005/8/22 4:58
Just popping in
Joined: 2005/8/21
From:
Posts: 17
 Re: Add Your Own Page Titles
thanks for your reply, I have been trying to get hold of the weblog people, I think my problem is understanding their code.

In the example you gave me, an individual entry ends up with the blog name as a page title, a category ends up with the name of the last individual entry on that category page as the title, og and the category ID appears to just be a number

its confusing not from the coding you are suggesting but working out how this module assigns category names and article titles

(sometime later)

ok I have altered both index.php and article.php and this gives a good result, however the category pages I still can't figure out.
macmend
Posted: 2005/8/22 8:41  Updated: 2005/8/22 8:41
Just popping in
Joined: 2005/8/21
From:
Posts: 17
 Re: Add Your Own Page Titles
after a struggle i found the part that puts the category name up and wonder if you could help...this is the part in index.php that defines the category but it displays as an html link

$path = $weblogcat->getNicePathFromId($entryObject->getVar('cat_id'),
sprintf('%s/modules/%s/index.php?user_id=%d',
XOOPS_URL, $xoopsModule->dirname(),
$user_id));

$entry['category'] = $path;

use of category like this:

$xoopsTpl->assign('xoops_pagetitle',
htmlentities($page_subtitle .
' -' . $xoopsModule->name() .
' -' . $entry['category'] ));

brings up a whole great long URL as well as the category name, is there anyway of seperating it out
tl001
Posted: 2005/8/22 8:55  Updated: 2005/8/22 10:13
Webmaster
Joined: 2004/6/10
From:
Posts: 282
 Re: Add Your Own Page Titles
You may want to try:

add this line after the pagetitle

$logcat =$weblogcat->getCategory($entryObject->getVar('cat_id'));


then
$xoopsTpl->assign('xoops_pagetitle',
htmlentities($page_subtitle .
' -' . $xoopsModule->name() .
' -' . $logcat ));

[edit] Be sure to get rid of PHPSessionIDs pended to your URLs. [/edit]
zigzag
Posted: 2005/8/30 7:24  Updated: 2005/8/30 7:24
Just popping in
Joined: 2005/7/31
From:
Posts: 2
 Re: Add Your Own Page Titles
Hello,
I would like to add page titles to individual events in the AM Events module but I can't seem to get it to work (I'm not a coder ) I've been fiddling with it all day & the nearest I've got is for each event page to be called "['event_name']" with the brackets

include ('header.php');
#include ('include/config.php');
#include_once ('include/functions.inc.php');
$myts =& MyTextSanitizer::getInstance();

//if (isset($_GET['cat_id'])) { $cat_id = $_POST['cat_id']; }

##################################################
#
if (!isset($_GET['id']) && !isset($_GET['v'])) {
// this page uses smarty template
// this must be set before including main header.php
$xoopsOption['template_main'] = 'event_index.html';
include XOOPS_ROOT_PATH.'/header.php';

$xoopsTpl->assign('eventlist_caption', _MD_EVENTLIST_CAPTION);
$xoopsTpl->assign('eventcol_caption', _MD_EVENTCOL_CAPTION);
$xoopsTpl->assign('datestartcol_caption', _MD_DATESTARTCOL_CAPTION);
$xoopsTpl->assign('dateendcol_caption', _MD_DATEENDCOL_CAPTION);
$xoopsTpl->assign('datedurcol_caption', _MD_DATEDURCOL_CAPTION);

$class = "even";

#$todaysdate = date("Y-m-d");

#$sql = ("SELECT * FROM " .$xoopsDB->prefix('amevents_events') . " WHERE event_date_start >= $todaysdate AND event_validated=1 AND event_showme=1 ORDER BY event_date_start ASC");
$sql = ("SELECT * FROM " .$xoopsDB->prefix('amevents_events') . " WHERE event_date_start >= NOW() AND event_validated=1 AND event_showme=1 ORDER BY event_date_start ASC");
$result=$xoopsDB->query($sql);
while($myrow = $xoopsDB->fetchArray($result)) {

$amevent = array();
$amevent['event_id'] = $myrow['id'];
$amevent['event_name'] = $myts->displayTarea($myrow['event_name'], 0, 0, 1, 0, 0);
$amevent['event_date_start'] = format_date($myrow['event_date_start'], $xoopsModuleConfig['datefrmt']);
$amevent['event_date_end'] = format_date($myrow['event_date_end'], $xoopsModuleConfig['datefrmt']);
$amevent['event_duration'] = $myrow['event_duration'];
$amevent['event_country'] = $myrow['event_country'];

if($class == "even") { $class = "odd"; }
else { $class = "even"; }
$amevent['event_class'] = $class;

if (!file_exists(XOOPS_ROOT_PATH ."/modules/amevents/images/flags/". $amevent['event_country'].".gif")) {
//echo XOOPS_ROOT_PATH . "/modules/amevents/images/flags/" . $amevent['event_country']. ".gif<br>";
$amevent['event_country'] = "00";
}

$xoopsTpl->append_by_ref('amevents', $amevent);
unset($amevent);
} // end while
#unset($category);
} // end if



#################################################
#
if (isset($_GET['id'])) {
$id = $_GET['id'];
//echo $cat_id;

$xoopsOption['template_main'] = 'event_item.html';
include XOOPS_ROOT_PATH.'/header.php';

$xoopsTpl->assign('index_link_text', _MD_INDEXLINKTEXT);
$xoopsTpl->assign('print_art_link', _MD_INDEXLINKPRINT);
$xoopsTpl->assign('email_friend', _MD_EMAIL);

$xoopsTpl->assign('eventview_caption', _MD_EVENTVIEW_CAPTION);
$xoopsTpl->assign('eventtitle_caption', _MD_EVENTTITLE_CAPTION);
$xoopsTpl->assign('eventstart_caption', _MD_EVENTSTART_CAPTION);
$xoopsTpl->assign('eventend_caption', _MD_EVENTEND_CAPTION);
$xoopsTpl->assign('eventdur_caption', _MD_EVENTDUR_CAPTION);
$xoopsTpl->assign('eventloc_caption', _MD_EVENTLOC_CAPTION);
$xoopsTpl->assign('eventurl_caption', _MD_EVENTURL_CAPTION);
$xoopsTpl->assign('eventdetails_caption', _MD_EVENTDETAILS_CAPTION);

$sql = ("SELECT * FROM " .$xoopsDB->prefix('amevents_events') . " WHERE id='$id' AND event_validated=1 AND event_showme=1");
#$sql = ("SELECT * FROM " .$xoopsDB->prefix('amevents_events') . " ORDER BY event_date_start ASC");
$result=$xoopsDB->query($sql);
while($myrow = $xoopsDB->fetchArray($result)) {

$amevent = array();
$amevent['event_id'] = $myrow['id'];
$amevent['event_name'] = $myts->displayTarea($myrow['event_name'], 0, 0, 1, 0, 0);
$amevent['event_date_start'] = format_date($myrow['event_date_start'], $xoopsModuleConfig['datefrmtmain']);
$amevent['event_date_end'] = format_date($myrow['event_date_end'], $xoopsModuleConfig['datefrmtmain']);
$amevent['event_duration'] = $myrow['event_duration'];
$amevent['event_description'] = $myts->displayTarea($myrow['event_description']);
$amevent['event_url'] = $myrow['event_url'];
$amevent['event_country'] = country($myrow['event_country']);

$xoopsTpl->append_by_ref('amevents', $amevent);
unset($amevent);
} // end while

} // end if

#################################################
#
if (isset($_GET['v'])) {

if (isset($_GET['y'])) { $year = $_GET['y']; }
if (isset($_GET['m'])) { $month = $_GET['m']; }
if (isset($_GET['d'])) { $day = $_GET['d']; }

$sqldate = $year . "-" . $month . "-" . $day;
#echo $sqldate;

// this page uses smarty template
// this must be set before including main header.php
$xoopsOption['template_main'] = 'event_indexday.html';
include XOOPS_ROOT_PATH.'/header.php';

$xoopsTpl->assign('index_link_text', _MD_INDEXLINKTEXT);

$xoopsTpl->assign('eventlist_caption', _MD_EVENTLIST_CAPTION);
$xoopsTpl->assign('eventcol_caption', _MD_EVENTCOL_CAPTION);
$xoopsTpl->assign('datestartcol_caption', _MD_DATESTARTCOL_CAPTION);
$xoopsTpl->assign('dateendcol_caption', _MD_DATEENDCOL_CAPTION);
$xoopsTpl->assign('datedurcol_caption', _MD_DATEDURCOL_CAPTION);

$class = "even";

#$todaysdate = date("Y-m-d");

#$sql = ("SELECT * FROM " .$xoopsDB->prefix('amevents_events') . " WHERE event_date_start >= $todaysdate AND event_validated=1 AND event_showme=1 ORDER BY event_date_start ASC");
$sql = ("SELECT * FROM " .$xoopsDB->prefix('amevents_events') . " WHERE event_date_start = '$sqldate' AND event_validated=1 AND event_showme=1 ORDER BY event_date_start ASC");
$result=$xoopsDB->query($sql);
while($myrow = $xoopsDB->fetchArray($result)) {

$amevent = array();
$amevent['event_id'] = $myrow['id'];
$amevent['event_name'] = $myts->displayTarea($myrow['event_name'], 0, 0, 1, 0, 0);
$amevent['event_date_start'] = format_date($myrow['event_date_start'], $xoopsModuleConfig['datefrmt']);
$amevent['event_date_end'] = format_date($myrow['event_date_end'], $xoopsModuleConfig['datefrmt']);
$amevent['event_duration'] = $myrow['event_duration'];
$amevent['event_country'] = $myrow['event_country'];

if($class == "even") { $class = "odd"; }
else { $class = "even"; }
$amevent['event_class'] = $class;

if (!file_exists(XOOPS_ROOT_PATH ."/modules/amevents/images/flags/". $amevent['event_country'].".gif")) {
//echo XOOPS_ROOT_PATH . "/modules/amevents/images/flags/" . $amevent['event_country']. ".gif<br>";
$amevent['event_country'] = "00";
}

$xoopsTpl->append_by_ref('amevents', $amevent);
unset($amevent);
} // end while
#unset($category);
} // end if

#############################################
#


###########
include XOOPS_ROOT_PATH.'/include/comment_view.php';
include XOOPS_ROOT_PATH.'/footer.php';
?>
tl001
Posted: 2005/8/30 10:36  Updated: 2005/8/30 10:36
Webmaster
Joined: 2004/6/10
From:
Posts: 282
 Re: Add Your Own Page Titles
A pagetitle is for an individual event not for a list of events.

What you are doing is trying to assign a pagetitle to a list of events.

$amevent['event_name'] =
$myts->displayTarea($myrow['event_name'], 0, 0, 1,
0, 0);

is an array and that is why you ended up with "['event_name']"
macmend
Posted: 2005/8/31 12:21  Updated: 2005/8/31 12:21
Just popping in
Joined: 2005/8/21
From:
Posts: 17
 Re: Add Your Own Page Titles
have only just tried your last suggestion...however it just comes up with -Object- in the title instead of the category
tl001
Posted: 2005/8/31 22:32  Updated: 2005/8/31 22:32
Webmaster
Joined: 2004/6/10
From:
Posts: 282
 Re: Add Your Own Page Titles
Sorry as I don't use it and can't help you further. I would suggest check the template file and php file to see how the category is assigned and go from there.

With or without the category should not be a big problem as pagetile tends to be cut off after certain number of characters.

Hope you have fixed the PHPSessionID problem. I would fix it first then worry about everything else. PHPSessionID creates content duplication problem which may well get your site penalized. All the SEO efforts mean nothing if a site gets penalized.
macmend
Posted: 2005/9/1 8:15  Updated: 2005/9/1 8:29
Just popping in
Joined: 2005/8/21
From:
Posts: 17
 Re: Add Your Own Page Titles
google did rather go round my site a couple of hundred times and use up all my bandwidth

so I have added the following in the htaaccess file:

php_flag session.use_trans_sid off

but am not sure how I can check this works
tl001
Posted: 2005/9/1 10:46  Updated: 2005/9/1 10:46
Webmaster
Joined: 2004/6/10
From:
Posts: 282
 Re: Add Your Own Page Titles
Quote:
php_flag session.use_trans_sid off


seems to be working. To be sure, check your logs to see if items crawled by googlebots are clean of PHPSessionID.
ianez
Posted: 2006/4/5 13:23  Updated: 2006/4/5 13:23
Just popping in
Joined: 2006/3/15
From:
Posts: 12
 Re: Add Your Own Page Titles
I've same problem with mylinks...
I need to have the category path of module in the page title.
Here's the code that make category_path in viewcat.php:
$pathstring = "<a href='index.php'>"._MD_MAIN."</a>&nbsp;:&nbsp;";
$pathstring .= $mytree->getNicePathFromId($cid, "title", "viewcat.php?op=");
$xoopsTpl->assign('category_path', $pathstring);
$xoopsTpl->assign('category_id', $cid);


I've tried
$xoopsTpl->assign('xoops_pagetitle', $pathstring);
but it return the long html link, while I need to have something like:
SiteTitle: Link-category1: sub-category:

how can I "clean" all this

thanx

IAn
tl001
Posted: 2006/4/5 15:36  Updated: 2006/4/5 21:28
Webmaster
Joined: 2004/6/10
From:
Posts: 282
 Re: Add Your Own Page Titles
You will have to decipher the html link into readable plain text pieces and re-join them together.

The challenge is to break the mytree->getNicePathFromId

It would be a very difficult task. I would suggest read the xoopstree function and then figure it out a way of breaking the three.

Personally, I will not attempt at doing that at all.

Maybe someone has better solutions? Anyone??
ianez
Posted: 2006/4/11 20:16  Updated: 2006/4/11 20:16
Just popping in
Joined: 2006/3/15
From:
Posts: 12
 Re: Add Your Own Page Titles
I assume that breaking the tree coul have consequences on other modules...
I hope another solution is possible...

I've tried changing it in
$xoopsTpl->assign('xoops_pagetitle', $pathstring('title'));

but it says the funciton () is undefined

Ian
ianez
Posted: 2006/4/13 9:35  Updated: 2006/4/13 9:35
Just popping in
Joined: 2006/3/15
From:
Posts: 12
 Re: Add Your Own Page Titles
Working with the staff of Xoopsit (Italian Xoops Support) we finally find the way.
In a few I'll send a detailed tip and a pdf
(the hack works also on other listing modules)

have a nice easter

Ian
macmend
Posted: 2006/11/14 11:04  Updated: 2006/11/14 11:06
Just popping in
Joined: 2005/8/21
From:
Posts: 17
 Re: Add Your Own Page Titles
I have played with this but don't get it, I want my title to be article title - Blog title

I have this code:

<?php
	$xoops_module_header = '
	<link rel="alternate" type="application/rss+xml" title="'.$xoopsModule->getVar('name').' entries" href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/feed/" />
	<link rel="alternate" type="application/rss+xml" title="'.$xoopsModule->getVar('name').' comments" href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/feed/" />
	';
	$GLOBALS["xoopsOption"]["xoops_module_header"] = $xoops_module_header;
	$GLOBALS["xoopsOption"]["xoops_pagetitle"] =$GLOBALS["xoopsModule"]->getVar("name")."".encoding_wp2xoops(wp_title('»', false));
	include_once(XOOPS_ROOT_PATH."/header.php");
	$xoopsTpl->assign('xoops_module_header', $xoops_module_header);
	$xoopsTpl->assign('xoops_pagetitle', $GLOBALS["xoopsOption"]["xoops_pagetitle"]);
	ob_start();
?>


I know this is the line that effects it but am not sure how to edit so that my page titles just have the name of the article and the name of the blog it can you help...?
$GLOBALS["xoopsOption"]["xoops_module_header"] = $xoops_module_header;