iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-26-2009, 09:17 AM
subho's Avatar
WebProWorld Member
 
Join Date: Sep 2005
Location: India
Posts: 87
subho RepRank 0
Default Dynamic <title> according to page URL

Hi All
I am new to php and trying to learn it.

I am developing a website using <?php include(''); ?> function. Entire website is divided into 5 templates such as "meta.php","header.php","navigation.php","righ t-menu.php", "footer.php". Till now <title>, <meta keywords>, <meta description> are static and place manually. I want these information to be dynamic from a .xml file stored inside server.

I am already able to fetch <meta keywords> and <meta descriptions> using php "simplexml_load_file". I want <title> to appear according to page URL/page name.I have few sets of <title> for each individual page inside .xml file. As an instance,for http://www.examplesite.com/vocal-science.php I have "Vocal Science" string.

Is it possible to fetch individual keywords from .xml file according to page URL? This is the solution I am looking for desperately. Any example or any tutorial is appreciable.

Thanks in advance
developersouvik
Web2.0 Designer
__________________
Developersouvik [Technology & creativity Spun together]
http://developersouvik.orgfree.com
Reply With Quote
  #2 (permalink)  
Old 07-26-2009, 01:15 PM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,648
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: Dynamic <title> according to page URL

Are you trying to copy someone else's web site?
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #3 (permalink)  
Old 07-26-2009, 02:14 PM
danlefree's Avatar
WebProWorld Pro
 
Join Date: Jun 2005
Location: Seattle
Posts: 268
danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4
Default Re: Dynamic <title> according to page URL

The simplexml_load_file documentation should include everything you need - there are numerous examples in the comments.

If you are not familiar with the PHP $_SESSION superglobal you will likely find that $_SERVER['REQUEST_URI'] is variable you have been looking for to map your XML data to individual URI's on your site (though, in the example below, my implementation uses the $_GET['page'] variable with a mod_rewrite directive instead).

Your solution will ultimately look something like this:

XML File:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<pages>
	<page>
		<uri>/</uri>
		<title>Homepage</title>
		<content>This is the homepage.</content>
	</page>
	<page>
		<uri>/vocal-science.php</uri>
		<title>Vocal Science</title>
		<content>This is the page about vocal science.</content>
	</page>
</pages>

index.php Code:

PHP Code:
<?php

define
'PATH_INCLUDES''/path/to/your/includes/' );
define'PATH_SITEFILE''/path/to/your/xml/file/' );

$page = array();

if ( 
file_existsPATH_SITEFILE ) ) {
    
$xml simplexml_load_filePATH_SITEFILE );
    
$count_pages count$xml->page );
    if ( 
$count_pages ) {
        for( 
$i 0$i $count_pages$i++ ) {
            
$page $xml->page[$i];
            if ( 
$page['uri'] == $_GET['page'] ) {
                
$page_display['title'] = $page['title'];
                
$page_display['content'] = $page['content'];
            }
        }
    } else {
        
$page_display['title'] = 'Error - No page information available';
        
$page_display['content'] = 'Site file found at ' PATH_SITEFILE ' contained no pages';
    }
} else {
    
$page_display['title'] = 'Error - Unable to load site file';
    
$page_display['content'] = 'Site file not found at ' PATH_SITEFILE;
}

// Include template file(s) which echo $page_display variables
require_once( PATH_INCLUDES 'template.inc.php' );

?>

mod_rewrite Directives:
Code:
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php?file=/$1 [L,QSA]
... that will probably work.
__________________
Dan LeFree | Product Manager (Linux VPS Hosting) | Owner/Operator (Web development, marketing)
Reply With Quote
  #4 (permalink)  
Old 07-26-2009, 03:18 PM
williamc's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jul 2003
Location: GoogleVille
Posts: 1,585
williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7
Default Re: Dynamic <title> according to page URL

Quote:
Originally Posted by wige View Post
Are you trying to copy someone else's web site?

I would ask the same before telling the guy how to do it. It is rather easy to accomplish, but let's see his need for it first.
__________________
William Cross
Expert Search Engine Optimization
Reply With Quote
  #5 (permalink)  
Old 07-26-2009, 04:28 PM
danlefree's Avatar
WebProWorld Pro
 
Join Date: Jun 2005
Location: Seattle
Posts: 268
danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4
Default Re: Dynamic <title> according to page URL

subho has 85 posts and he has been a member here since 2005... I'd give him the benefit of the doubt on this one.

Anyone interested in copying a site's content has many, many options (almost all of which are more convenient than coding up a PHP script to read an XML file) - and anyone who has been a user on this site for four years should know better than to serve up duplicate content
__________________
Dan LeFree | Product Manager (Linux VPS Hosting) | Owner/Operator (Web development, marketing)
Reply With Quote
  #6 (permalink)  
Old 07-26-2009, 04:37 PM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,648
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: Dynamic <title> according to page URL

While I agree it is probable that he is not copying another site, I am just suspicious by nature I suppose. However, if the content that will be used as the title and keywords is being stored locally, there might be more efficient ways of doing this - such as reading the information from a database, unless he is pulling a file from another website, where his options become more limited.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #7 (permalink)  
Old 07-26-2009, 05:57 PM
williamc's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jul 2003
Location: GoogleVille
Posts: 1,585
williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7williamc RepRank 7
Default Re: Dynamic <title> according to page URL

import xml to mysql, then select * from tablename where url like '%specific urlpart%' then echo culled data where applicable.
__________________
William Cross
Expert Search Engine Optimization
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Home page Dynamic Vs Html static page Steven1976a Search Engine Optimization Forum 4 05-27-2007 07:10 PM
Dynamic Title and Desc Tags - BAD??????? schmeetz Search Engine Optimization Forum 3 11-09-2006 01:04 PM
Dynamic keyword list and title bedford Search Engine Optimization Forum 1 02-21-2005 04:57 PM
Dynamic Page Title Steven Glover Search Engine Optimization Forum 3 08-02-2004 10:57 PM
Formatting Meta tags: title VS DC.title VS http-equiv=title Sergio Simarro Search Engine Optimization Forum 8 05-27-2004 12:48 PM


All times are GMT -4. The time now is 12:26 PM.



Search Engine Optimization by vBSEO 3.3.0