0

I have an xml database where are stocked several blog posts.

xml example:

<element id="12" size="square" category="portfolio">
    <tag tag="printer printing 3d apple iphone 5 bumper case"></tag>
    <icon class="icon-picture"></icon>
    <urlpage url="/contact/contact.html"></urlpage>
    <urlimage src='./Post thumbnail images/01.png'></urlimage>
    <date date="8 Apr"></date>
    <title>Minimal Bumper for iPhone 5 : Protect your iphone with a lightwheight and protect full case </title>
</element>

I want to have my website based on two main php pages. The main index.php page where blog post thumbnails and links are displayed. And a single.php page where each blog posts can be displayed individually.

How can I load, change the content and url of the single.php page when I click on a blog post thumbnail link in the index.php page (finally, I think, like wordpress but without use it)?

If this is possible, how it works for SEO?

Sorry for my english, I'm french.

freaky
  • 990
  • 3
  • 17
  • 44

2 Answers2

2

You can do this by using GET variables which you will set in the url:

for single.php, url www.example.com.php?blog_no=121

if(isset($_GET["blog_no"])) {
     // connect to database and get post
}

You need to set $_GET variable in the url when linking to that post: on the index.php page you would

<a href="single.php?blog_no=121">Post 121</a>
Ace
  • 152
  • 10
  • Are `$_GET` variables already set? – Fabio May 18 '13 at 11:54
  • no you would pass them through the url for when linking to that post, eg on index.php Post 121 – Ace May 18 '13 at 11:56
  • I think this should have been in your answer – Fabio May 18 '13 at 11:56
  • On single.php you are checking to see if a variable has been set in the url. You can then use this variable to search the database and check for that post. – Ace May 18 '13 at 12:02
  • ok thank you. And if I write this url directly in the browser does it load the right content? Is it SEO friendly? – freaky May 18 '13 at 12:02
  • You can make it seo friendly using an htaccess to remove the .php?blog_no= so you are left with single/121 – Ace May 18 '13 at 12:04
  • ok. Thank you. I will try all this and ask later if I have some trouble. I'm new in php. And I was thinking it was very complicated to do this kind of things before your answere... – freaky May 18 '13 at 12:06
  • I succes to load the single.php file. However I have a problem to get the correct content from xml. If I set xml node from the isset variable it don't work : `if(isset($_GET["blog_no"])) { $i = $_GET["blog_no"]; $elements = new SimpleXMLElement('data.xml', null, true); echo $i; echo $elements->element[$i]['size']; echo $elements->element[$i]['category']; }` – freaky May 18 '13 at 18:30
  • you would use the blog_no from the url to search the xml file – Ace May 18 '13 at 18:53
  • But I have only one xml data file. I want to search find in xml nodes... – freaky May 18 '13 at 18:55
0

First of all, you can add in your database for each post, a field named "url", where you can define a custom url for every post. You can use the rewrite url rule in .htaccess. Here is a link with some pretty nice examples of how this works: example

On your single.php you can load your content dynamical from your database.

Codrutz Codrutz
  • 472
  • 5
  • 15