animedls Posted September 27, 2006 Share Posted September 27, 2006 Hi all , im new to this forum and have posted this question elsewhere on other forums but have not been able to get an answer .i have purchased a site www.animedls.com about 1 month ago and i am in the middle of updating the site and doing some seo work on it. I believe that my site runs from a template and it just inserts the .php page into the template (i dont know what template it uses). If you have a look at site , the title tags stay the same for all the pages .My question is how do i generate title tags for each individual page so that the title tag relates to the actual .php and i do not just have one title tag for all pages in the site ? I am noob when it comes to php so any help is very much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/ Share on other sites More sharing options...
alpine Posted September 27, 2006 Share Posted September 27, 2006 The principal could be like this example, include title-php stuff above the html title tag:[code]<?phpswitch($_GET['page']){ case 'home': $title = "Welcome"; break; case 'about': $title = "About us"; break; // etc etc}?><!-- html starts --><head><title><?php echo $title; ?></title></head>[/code]So for example "index.php?page=about" would generate the title "About us" in this case.If you query for example mysql for articles and want the article title as html title, run query instead of the switch example and declare article title as $title. Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-99655 Share on other sites More sharing options...
animedls Posted September 28, 2006 Author Share Posted September 28, 2006 hi , can you explain a little simpler , ima noob to php. could you do it in steps for me ? Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100110 Share on other sites More sharing options...
wildteen88 Posted September 28, 2006 Share Posted September 28, 2006 Hi welcome to phpfreaks.comI would recommend you to read up on the [url=http://php.net/switch]switch statement[/url] if you dont understand the code. it is basically an if/elseif statement.But this is what the code is doing.It is grabing a [b]url variable[/b] called [b]page[/b] (example url: mysite.com/index.php?page=home) you can access this variable by using [b]$_GET['page'][/b]. Now it creates a variable called [b]title[/b] ($title) based on the value of the page variable ($_GET['page']). So if page is set to home, it'll trigger the first case in the switch, which is home and set the title variable to hold the string [b]Welcome[/b]. If its not home it'll check to see if page is set to about. If its it'll set the title variable to hold the string [b]About Us[/b].Now on this line it echos out the titile variable:[code]<title><?php echo $title; ?></title>[/code]Hope that helps. The manual shoudl be able to clear up on how the swtich statement actually works. Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100129 Share on other sites More sharing options...
animedls Posted September 28, 2006 Author Share Posted September 28, 2006 by doing this, is this something that the search engines could spider ? Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100142 Share on other sites More sharing options...
mendoz Posted September 28, 2006 Share Posted September 28, 2006 Yeah, because the output is for example:for the page index.php?page=homethe output will be<title>home</title> Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100147 Share on other sites More sharing options...
steveclondon Posted September 28, 2006 Share Posted September 28, 2006 This is also a good thing because search engines will also look at the name of you page and if it sees keywords in this as well that can help. If you wanted to go one better you could do a mod-rewrite. Anyway sorry I have strayed a bit from what you were asking there. Have you looked at keywords and description, you should still have unique keywords and descriptions on your pages, although some say not. Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100150 Share on other sites More sharing options...
animedls Posted September 28, 2006 Author Share Posted September 28, 2006 so i could generate title tags by php as well as the meta desciption and meta keywords tags? Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100151 Share on other sites More sharing options...
steveclondon Posted September 28, 2006 Share Posted September 28, 2006 yes you could. How easy that is depends on the data already available to you or how you structure your data. If you are willing to through some time in and plan it out first then you could do a fairly effective range unique keywords and descriptions. Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100152 Share on other sites More sharing options...
animedls Posted September 28, 2006 Author Share Posted September 28, 2006 woudl anyone be willing to do the title tags code on one page for me so i can see the structure of the code and then i could replicate this on all other pages/for other pages . I will give you cpanel access , just one live example and then i'll be able to replicate for all the other pages i have Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100155 Share on other sites More sharing options...
wildteen88 Posted September 28, 2006 Share Posted September 28, 2006 By live example you mena something like this:[code]<?php// check that page is set and that its not empty, if it is set and not empty we'll use the page variable// else we'll set it to a efualt value which is home$page = isset($_GET['page']) && !empty($_GET['page']) ? $_GET['page'] : 'home';switch($page){ case 'home': $title = "Welcome"; $content = 'Welcome home dude!'; break; case 'about': $title = "About us"; $content = 'so you wanno know stuff about me!'; break; case 'products': $title = 'My products'; $content = 'Hey the following are my products'; break; default: $title = '404 Error'; $content = "Sorry the page '<i>" . $page . "</i>' you reguested was not found. Please try again"; break;}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title><?php echo $title; ?></title></head><body><h1><?php echo $title; ?></h1><p><?php echo $content; ?></p><p> <hr /> Pages: <a href="?page=home">Home</a> | <a href="?page=about">About Us</a> | <a href="?page=products">Products</a> | <a href="?page=duffPage">A duff page</a></p></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100284 Share on other sites More sharing options...
animedls Posted September 28, 2006 Author Share Posted September 28, 2006 i think i unedrstand but i tkae it , i would have tochaneg all my urls/links on the site to the format "?page=blahblah" I only include this code on the index page right ? Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100290 Share on other sites More sharing options...
jerastraub Posted September 28, 2006 Share Posted September 28, 2006 If your e-commerce store is running off a database you may try something like <? include("config.php"); ?><title><?// Get 1 Category Title Below$result = mysql_query("SELECT * FROM womensproducts WHERE CategoryID='$cat' limit 1") or die (mysql_error());while ($row = mysql_fetch_array($result)){include("title.php");}mysql_free_result($result);?>Which my title.php just includes: <?=$row["Category"]; ?>You can change this variable to whatever your wanting to change on each page.Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100303 Share on other sites More sharing options...
wildteen88 Posted September 28, 2006 Share Posted September 28, 2006 [quote author=animedls link=topic=109704.msg443099#msg443099 date=1159454831]i think i unedrstand but i tkae it , i would have tochaneg all my urls/links on the site to the format "?page=blahblah" I only include this code on the index page right ? [/quote]No. Just chnage [b]page[/b] in the $_GET var to the name of the variable that holds the page that is being reguested.What is the format of the urls? Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100309 Share on other sites More sharing options...
animedls Posted September 28, 2006 Author Share Posted September 28, 2006 examples of my urls :http://www.animedls.com/content-media,complete%20anime%20episodeshttp://www.animedls.com/content-media,complete%20cowboy%20bebop%20episodes Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100317 Share on other sites More sharing options...
wildteen88 Posted September 28, 2006 Share Posted September 28, 2006 Umm looks like you're using mod_rewrite. Could you post the the urls in their raw state you should be able to get these by looking in the htaccess file that does the mod_rewrite. Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100319 Share on other sites More sharing options...
alpine Posted September 28, 2006 Share Posted September 28, 2006 This will be a variant:[code]<?php$is_url = $_SERVER['REQUEST_URI'];$is_piece = explode(",", $is_url);$title = urldecode($is_piece[1]);?>[/code]On your first link example the title then becomes "complete anime episodes"On the second link it is "complete cowboy bebop episodes" Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100338 Share on other sites More sharing options...
animedls Posted September 28, 2006 Author Share Posted September 28, 2006 im completely lost , ive hired a freelancer for $80 to complete work Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100339 Share on other sites More sharing options...
alpine Posted September 28, 2006 Share Posted September 28, 2006 All you'de have to do was include my last code on top of every page and echo $title out within the title tags.But if you give up and decide to hire a freelancer on this issue, you obviously aren't seeking to learn the magic of php 8) Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100344 Share on other sites More sharing options...
animedls Posted September 28, 2006 Author Share Posted September 28, 2006 was trying to but got to hard to understand and ddidnt want to mess up site Quote Link to comment https://forums.phpfreaks.com/topic/22251-i-want-to-use-php-to-generate-title-tags/#findComment-100347 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.