This mod outputs a dynamic (ever changing) page title for your web pages. Essentially this adds the clickstream to your page title but without the added HTML markup.
If your site name is defined as "Smith Family Pictures" and you were viewing a details.php page for an image named "Old Bridge" in a subcategory named "Road Trip" which was a subcategory of a top-level "2005 Events" category and your admin control panel setting for "Category delimiter (in category paths)" was defined as "/", your page title would look like this: Smith Family Pictures /2005 Events/Road Trip/Old Bridge
As with any mod, ALWAYS save backup copies of any file you might edit so you can go back to a clean, working version if you encounter any problems.
Open includes/functions.php, locate:
function get_category_path($cat_id = 0, $detail_path = 0) {
global $site_sess, $config, $cat_cache, $url;
$parent_id = 1;
while ($parent_id) {
if (!isset($cat_cache[$cat_id]['cat_parent_id'])) {
return false;
}
$parent_id = $cat_cache[$cat_id]['cat_parent_id'];
if (empty($path)) {
if ($detail_path) {
$cat_url = ROOT_PATH."categories.php?".URL_CAT_ID."=".$cat_id;
if (preg_match("/".URL_PAGE."=([0-9]+)/", $url, $regs)) {
if (!empty($regs[1]) && $regs[1] != 1) {
$cat_url .= "&".URL_PAGE."=".$regs[1];
}
}
$path = "<a href=\"".$site_sess->url($cat_url)."\" class=\"clickstream\">".$cat_cache[$cat_id]['cat_name']."</a>";
}
else {
$path = $cat_cache[$cat_id]['cat_name'];
}
}
else {
$path = "<a href=\"".$site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$cat_id)."\" class=\"clickstream\">".$cat_cache[$cat_id]['cat_name']."</a>".$config['category_separator'].$path;
}
$cat_id = $parent_id;
} // end while
return $path;
}
Add after:
function get_category_path_nohtml($cat_id = 0) { // MOD: Dynamic page title
global $config, $cat_cache;
$parent_id = 1;
while ($parent_id) {
if (!isset($cat_cache[$cat_id]['cat_parent_id'])) {
return false;
}
$parent_id = $cat_cache[$cat_id]['cat_parent_id'];
if (empty($path)) {
$path = $cat_cache[$cat_id]['cat_name'];
}
else {
$path = $cat_cache[$cat_id]['cat_name'].$config['category_separator'].$path;
}
$cat_id = $parent_id;
} // end while
return $path;
}
Open categories.php, locate:
$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].get_category_path($cat_id)."</span>";
Add after:
$page_title = $config['category_separator'].get_category_path_nohtml($cat_id); // MOD: Dynamic page title
Locate:
$site_template->register_vars(array(
"msg" => $msg,
"clickstream" => $clickstream
));
Change to:
$site_template->register_vars(array(
"msg" => $msg,
"clickstream" => $clickstream,
"page_title" => $page_title // MOD: Dynamic page title
));
Open details.php, locate:
$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'];
Add after:
$page_title = $config['category_separator'].$lang['home'].$config['category_separator']; // MOD: Dynamic page title
Locate:
$clickstream .= "<a href=\"".$site_sess->url(ROOT_PATH."lightbox.php".$page_url)."\" class=\"clickstream\">".$lang['lightbox']."</a>".$config['category_separator'];
Add after:
$page_title = $config['category_separator'].$lang['lightbox'].$config['category_separator']; // MOD: Dynamic page title
Locate:
$clickstream .= "<a href=\"".$site_sess->url(ROOT_PATH."search.php?show_result=1".$page_url)."\" class=\"clickstream\">".$lang['search']."</a>".$config['category_separator'];
Add after:
$page_title = $config['category_separator'].$lang['search'].$config['category_separator']; // MOD: Dynamic page title
Locate:
$clickstream .= get_category_path($cat_id, 1).$config['category_separator'];
Add after:
$page_title = $config['category_separator'].get_category_path_nohtml($cat_id).$config['category_separator']; // MOD: Dynamic page title
Locate:
$clickstream .= $image_name."</span>";
Add after:
$page_title .= $image_name; // MOD: Dynamic page title
Locate:
$site_template->register_vars(array(
"msg" => $msg,
"clickstream" => $clickstream,
CHANGE to:
$site_template->register_vars(array(
"msg" => $msg,
"clickstream" => $clickstream,
"page_title" => $page_title, // MOD: Dynamic page title
Open index.php, locate:
if (!empty($template)) {
$clickstream = "<a href=\"".$site_sess->url(ROOT_PATH."index.php")."\">".$lang['home']."</a>".$config['category_separator'].str_replace("_", " ", ucfirst($template));
Add after:
$page_title = $config['category_separator'].str_replace("_", " ", ucfirst($template)); // MOD: Dynamic page title
Locate:
$site_template->register_vars("clickstream", $clickstream);
CHANGE to:
$site_template->register_vars(array(
"clickstream" => $clickstream,
"page_title" => $page_title // MOD: Dynamic page title
));
On the next line down, locate:
$site_template->print_template($site_template->parse_template($main_template));
include(ROOT_PATH.'includes/page_footer.php');
}
CHANGE this to:
$site_template->print_template($site_template->parse_template($main_template));
include(ROOT_PATH.'includes/page_footer.php');
} else { // MOD: Dynamic page title
$page_title = $config['category_separator'].$lang['home'];
$site_template->register_vars("page_title", $page_title);
}
Locate:
//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
"msg" => $msg,
"clickstream" => $clickstream
));
CHANGE this to:
//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
"msg" => $msg,
"clickstream" => $clickstream,
"page_title" => $page_title // MOD: Dynamic page title
));
Open lightbox.php, locate:
//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].$lang['lightbox']."</span>";
Add after:
$page_title = $config['category_separator'].$lang['lightbox']; // MOD: Dynamic page title
Locate:
$site_template->register_vars(array(
"msg" => $msg,
"clickstream" => $clickstream,
CHANGE this to:
$site_template->register_vars(array(
"msg" => $msg,
"clickstream" => $clickstream,
"page_title" => $page_title, // MOD: Dynamic page title
Open member.php, locate:
//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].$txt_clickstream."</span>";
Add after:
$page_title = $config['category_separator'].$txt_clickstream; // MOD: Dynamic page title
Locate:
$site_template->register_vars(array(
"content" => $content,
"msg" => $msg,
"clickstream" => $clickstream,
CHANGE this to:
$site_template->register_vars(array(
"content" => $content,
"msg" => $msg,
"clickstream" => $clickstream,
"page_title" => $page_title, // MOD: Dynamic page title
Open register.php, locate:
//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].$lang['register']."</span>";
Add after:
$page_title = $config['category_separator'].$lang['register']; // MOD: Dynamic page title
Locate:
$site_template->register_vars(array(
"content" => $content,
"msg" => $msg,
"clickstream" => $clickstream,
CHANGE this to:
$site_template->register_vars(array(
"content" => $content,
"msg" => $msg,
"clickstream" => $clickstream,
"page_title" => $page_title, // MOD: Dynamic page title
Open search.php, locate:
//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].$lang['search']."</span>";
CHANGE this to:
//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
// $clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].$lang['search']."</span>"; // Original code
// MOD: Dynamic page title BLOCK BEGIN
if (!empty($search_id['search_new_images'])) {
if( $search_id['search_new_images'] == 1 )
$txt_clickstream = $lang['new_images'];
else
$txt_clickstream = $lang['new_images_since'];
}
else {
$txt_clickstream = $lang['search'];
}
$clickstream = "<span class=\"clickstream\"><a title=\"".$lang['home']."\" href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].(($search_keywords) ? "<a href=\"".$site_sess->url(ROOT_PATH."search.php")."\" class=\"clickstream\">".$lang['search']."</a>".$config['category_separator'].$search_keywords : $txt_clickstream)."</span>"; // Show search keywords
$page_title = $config['category_separator'].$txt_clickstream;
// MOD: Dynamic page title BLOCK END
Locate:
$site_template->register_vars(array(
"content" => $content,
"msg" => $msg,
"clickstream" => $clickstream,
CHANGE this to:
$site_template->register_vars(array(
"content" => $content,
"msg" => $msg,
"clickstream" => $clickstream,
"page_title" => $page_title, // MOD: Dynamic page title
Open top.php, locate:
//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'];
if ($cat_id && isset($cat_cache[$cat_id])) {
$clickstream .= get_category_path($cat_id, 1).$config['category_separator'];
}
$clickstream .= $lang['top_images']."</span>";
CHANGE this to:
//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream = "<span class=\"clickstream\"><a title=\"".$lang['home']."\" href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'];
$page_title = $config['category_separator']; // MOD: Dynamic page title
if ($cat_id && isset($cat_cache[$cat_id])) {
$clickstream .= get_category_path($cat_id, 1).$config['category_separator'];
$page_title .= get_category_path_nohtml($cat_id).$config['category_separator']; // MOD: Dynamic page title
}
$clickstream .= $lang['top_images']."</span>";
$page_title .= $lang['top_images']; // MOD: Dynamic page title
Locate:
$site_template->register_vars(array(
"msg" => $msg,
"clickstream" => $clickstream,
CHANGE this to:
$site_template->register_vars(array(
"msg" => $msg,
"clickstream" => $clickstream,
"page_title" => $page_title, // MOD: Dynamic page title
Open templates/default/header.html, locate:
<title>{site_name}</title>
CHANGE this to:
<title>{site_name} {page_title}</title>
IF you are using version 1.7, you are finished STOP HERE
IF you are using version 1.7.1 which has a new template processing engine, you will also need to do the following steps:
Open includes/functions.php, locate:
function show_error_page($error_msg, $clickstream = "") {
global $site_template, $site_sess, $lang, $config;
if (empty($clickstream)) {
$clickstream = "<a href=\"".$site_sess->url(ROOT_PATH."index.php")."\">".$lang['home']."</a>".$config['category_separator'].$lang['error'];
}
$site_template->register_vars(array(
"error_msg" => $error_msg,
"lang_error" => $lang['error'],
"clickstream" => $clickstream,
"random_image" => ""
));
$site_template->print_template($site_template->parse_template("error"));
exit;
}
Change this to:
function show_error_page($error_msg, $clickstream = "") {
global $site_template, $site_sess, $lang, $config;
if (empty($clickstream)) {
$clickstream = "<a href=\"".$site_sess->url(ROOT_PATH."index.php")."\">".$lang['home']."</a>".$config['category_separator'].$lang['error'];
}
$site_template->register_vars(array(
"error_msg" => $error_msg,
"lang_error" => $lang['error'],
"clickstream" => $clickstream,
"random_image" => ""
));
// MOD: Dynamic page title BLOCK BEGIN
$header = $site_template->parse_template("header");
$footer = $site_template->parse_template("footer");
$site_template->register_vars(array(
"header" => $header,
"footer" => $footer
));
unset($header);
unset($footer);
// MOD: Dynamic page title BLOCK END
$site_template->print_template($site_template->parse_template("error"));
exit;
}
Open includes/page_header.php, locate:
//-----------------------------------------------------
//--- Parse Header & Footer ---------------------------
//-----------------------------------------------------
if (isset($main_template) && $main_template) {
$header = $site_template->parse_template("header");
$footer = $site_template->parse_template("footer");
$site_template->register_vars(array(
"header" => $header,
"footer" => $footer
));
unset($header);
unset($footer);
}
We need to move this logic to each of the top-level php files, so comment out this code by replacing it with:
/********** ORIGINAL
//-----------------------------------------------------
//--- Parse Header & Footer ---------------------------
//-----------------------------------------------------
if (isset($main_template) && $main_template) {
$header = $site_template->parse_template("header");
$footer = $site_template->parse_template("footer");
$site_template->register_vars(array(
"header" => $header,
"footer" => $footer
));
unset($header);
unset($footer);
}
**********/
Open categories.php, details.php, index.php, lightbox.php, member.php, postcards.php, register.php, search.php, top.php and locate this line:
$site_template->print_template($site_template->parse_template($main_template));
On a new line ABOVE that line, paste this
// MOD: Dynamic page title BLOCK BEGIN
//-----------------------------------------------------
//--- Parse Header & Footer ---------------------------
//-----------------------------------------------------
if (isset($main_template) && $main_template) {
$header = $site_template->parse_template("header");
$footer = $site_template->parse_template("footer");
$site_template->register_vars(array(
"header" => $header,
"footer" => $footer
));
unset($header);
unset($footer);
}
// MOD: Dynamic page title BLOCK END
NOTE: There are TWO places inside index.php this needs to be done. All the other PHP files listed above have only ONE.
Revision History:
* Bug fix in includes/functions.php show_error_page() for version 1.7.1
* Added support for version 1.7.1. I do not like the solution as it is a hack but it works.
* Corrected a typo in the edit needed for categories.php