Grabbing Category Name for <title>
Posted: Tue May 30, 2006 10:10 am
I want to use the directory script at IndexScript.com but the page titles it generates are pulled from a global setting so ALL page titles are the same. I want to modify it so that if I am in category 2 (show_cat.php?cat_id=2) instead of this pages title being what ever you set $meta_title as, I want it to pull from the name of what the category is.
Ultimatley I'd like to write a function that will pull both the title of the category and the description from the database that I can include in show_cat.php so I can dynamically change the <title> tag and Meta Description tag depending on what category is selected.
I hope someone can help me!
Just to let you know, the data base structure for the category table is as follows:
show_cat.php
Ultimatley I'd like to write a function that will pull both the title of the category and the description from the database that I can include in show_cat.php so I can dynamically change the <title> tag and Meta Description tag depending on what category is selected.
I hope someone can help me!
Just to let you know, the data base structure for the category table is as follows:
Code: Select all
cat_id, parent_id, name, description, indexdisplay
8, 1, Test, Test Description, Y,Code: Select all
<?php
//////////////////////////////////////////////////////////////////////
// expects $_GET values for:
// 1. cat_id
// 2. page
//////////////////////////////////////////////////////////////////////
session_start();
///////////////////////////////////////////////////////////////////////////
// get meta information
///////////////////////////////////////////////////////////////////////////
include_once("config.php");
mysql_connect($db_host, $db_login, $db_pwd) or die("Cannot connect to DB!");
mysql_select_db($db_name) or die("Cannot select DB!");
$sql = "select meta_title, meta_description, meta_keywords, seo_urls from dir_settings limit 1";
$rst = mysql_query($sql);
if(mysql_affected_rows() == 0) {
$meta_title = "";
$meta_description = "";
$meta_keywords = "";
$seo_urls = "N";
}
else {
$row = mysql_fetch_array($rst);
$meta_title = $row['meta_title'];
$meta_description = $row['meta_description'];
$meta_keywords = $row['meta_keywords'];
$seo_urls = $row['seo_urls'];
}
mysql_close();
?>
<?php
mysql_connect($db_host, $db_login, $db_pwd) or die("Cannot connect to DB!");
mysql_select_db($db_name) or die("Cannot select DB!");
$sql = "select cat_id, name from dir_cat where parent_id = " . $start_id;
$rst = mysql_query($sql);
mysql_close();
?>
<html>
<head>
<title><?php echo($path); ?> <?php echo($_GET['name']); ?></title>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="<?php echo($meta_description); ?>">
<meta name="keywords" content="<?php echo($meta_keywords); ?>">
<link href= <?php echo($dir_root_path . "style/styles.css"); ?> rel="stylesheet" type="text/css">
</head>
<body>
<div align="center">
<div id="container">
<?php
if($_SESSION["logged_in"] == "yes") {
include('./style/header_adm.php');
print "<center><br><br><a href=\"" . $dir_root_path . "add_cat.php?parent_id=". $_GET['cat_id'] . "\">
Add Sub-category</a>  |  ";
print "<a href=\"" . $dir_root_path . "pend_cat.php" . "\">Pending Categories</a>  |  ";
print "<a href=\"" . $dir_root_path . "pend_url.php" . "\">Pending URLs</a>  |  ";
print "<a href=\"" . $dir_root_path . "stats.php" . "\">Stats</a>  |  ";
print "<a href=\"" . $dir_root_path . "settings.php" . "\">Settings</a><br><br></center>";
}
else {
include('./style/header.php');
}
?>
<div id="content">
<?php
include_once("./include/utils.php");
mysql_connect($db_host, $db_login, $db_pwd) or die("Cannot connect to DB!");
mysql_select_db($db_name) or die("Cannot select DB!");
///////////////////////////////////////////////////////////////////////////
// display intermediate menu
///////////////////////////////////////////////////////////////////////////
//
print "<div id=\"intermenu\">";
print "<a href=\"" . $dir_root_path . "SuggestCategory.php?parent_id=" . $_GET['cat_id'] . "\">Suggest Category</a> | " . "<a href=\"" . $dir_root_path . "add.php?cat_id=" . $_GET['cat_id'] . "\">Add URL</a>";
print "</div>";
///////////////////////////////////////////////////////////////////////////
// get the path to current category
///////////////////////////////////////////////////////////////////////////
$path = fngetcatpath($_GET['cat_id'], $dir_root_path);
print $path . " <br><br><br>";
///////////////////////////////////////////////////////////////////////////
// get the existing sub-categories
///////////////////////////////////////////////////////////////////////////
print "<div id=\"intermediate\">";
print "<br>Sub-categories in this category:<br><br>";
fndisplaysubcats($_GET['cat_id'], $dir_root_path);
///////////////////////////////////////////////////////////////////////////
// display featured sites
///////////////////////////////////////////////////////////////////////////
$sql = "select title, description, url,name from dir_url where " .
"cat_id = " . fnpreparesql($_GET['cat_id']) . " and " .
"featured = 'Y' order by title";
$rst = mysql_query($sql);
if(mysql_affected_rows() > 0) {
print "<br>";
print "<div id=\"feature\">";
print "<br>Featured URLs in this category:<br><br>";
while($row = mysql_fetch_array($rst)) :
print "<a href=\"" . $row['url'] . "\">" . $row['title'] . "</a>";
if($_SESSION["logged_in"] == "yes") {
print "  [<a href=\"" . $dir_root_path . "edit_url.php?cat_id=" . $_GET['cat_id'] .
"&url=" . $row['url'] . "&src=app\">EDIT</a>]";
}
print "<br><span class=\"sub-text\">" . $row['description'] . "<br>" .
"<a href=\"" . $row['url'] . "\">" . $row['url'] . "</a></span><br><br>";
endwhile;
print "</div>";
}
print "<br></div>";
///////////////////////////////////////////////////////////////////////////
// get display order
///////////////////////////////////////////////////////////////////////////
$display_order = fngetdisplayorder();
///////////////////////////////////////////////////////////////////////////
// display listed urls in this category
///////////////////////////////////////////////////////////////////////////
print "<br><br><br>Resources listed in this category:<br><br><br>";
$sql = "select title, description, url from dir_url where " .
"cat_id = " . fnpreparesql($_GET['cat_id']);
if($display_order == 1) {
$sql = $sql . " order by date";
}
else {
$sql = $sql . " order by title";
}
$rst = mysql_query($sql);
if(mysql_affected_rows() == 0) {
print "None";
}
else {
$page = $_GET['page'];
if($page == 0) {
$page = 1;
}
mysql_data_seek($rst, ($page - 1) * 20);
$cnt = ($page - 1) * 20;
while($cnt < mysql_affected_rows() && $cnt < $page * 20) :
$row = mysql_fetch_array($rst);
print "<a href=\"" . $row['url'] . "\">" . $row['title'] . "</a>";
if($_SESSION["logged_in"] == "yes") {
print "  [<a href=\"" . $dir_root_path . "edit_url.php?cat_id=" . $_GET['cat_id'] .
"&url=" . $row['url'] . "&src=app\">EDIT</a>]";
print "  [<a href=\"" . $dir_root_path . "del_rec.php?item=url&cat_id=" . $_GET['cat_id'] .
"&url=" . $row['url'] . "&src=app\">DELETE</a>]";
}
print "<br><span class=\"sub-text\">" . $row['description'] . "<br>" .
//href the url to the url "<a href=\"" . $row['url'] . "\">" . $row['url'] . "</a></span><br><br><br>";
$row['url'] ."</span><br><br><br>";
$cnt = $cnt + 1;
endwhile;
if(mysql_affected_rows() > 20) {
$pagecnt = ceil(mysql_affected_rows() / 20);
print "<br><br><br><center>Page " . $page . " of " . $pagecnt . ". ";
if($seo_urls == "Y") {
print "<a href=\"" . $dir_root_path . "cat/" . $_GET['cat_id'] . "/page/1/\">First</a> ";
if($page > 1) {
print " | <a href=\"" . $dir_root_path . "cat/" . $_GET['cat_id'] . "/page/" . ($page - 1) . "/\">Prev</a> ";
}
if($page < $pagecnt) {
print " | <a href=\"" . $dir_root_path . "cat/" . $_GET['cat_id'] . "/page/" . ($page + 1) . "/\">Next</a> ";
}
print " | <a href=\"" . $dir_root_path . "cat/" . $_GET['cat_id'] . "/page/" . $pagecnt . "/\">Last</a></center>";
}
else {
print "<a href=\"". $dir_root_path . "show_cat.php?cat_id=" . $_GET['cat_id'] . "&page=1\">First</a> ";
if($page > 1) {
print " | <a href=\"" . $dir_root_path . "show_cat.php?cat_id=" . $_GET['cat_id'] . "&page=" . ($page - 1) . "\">Prev</a> ";
}
if($page < $pagecnt) {
print " | <a href=\"" . dir_root_path . "show_cat.php?cat_id=" . $_GET['cat_id'] . "&page=" . ($page + 1) . "\">Next</a> ";
}
print " | <a href=\"" . $dir_root_path . "show_cat.php?cat_id=" . $_GET['cat_id'] . "&page=" . $pagecnt . "\">Last</a></center>";
}
}
}
mysql_close();
?>
</div>
</div>
<?php include('./style/footer.php'); ?>
</div>
</body>
</html>