Search code examples
phpdatabasesinglepage

one php page with different contents and urls


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.


Solution

  • 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>