简体   繁体   中英

How to create dynamic url and content like wordpress in php?

I want to create dynamic url and content like wordpress platform but I am doing something wrong. Kindly check my code:

<?php

$pages = array("story1", "story2", "story3");

?>



<!DOCTYPE html>
<html lang="en-US">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>This is my page title.</title>
 <link rel="canonical" href="http://www.xyz1.com/kids-english-<?php 
 echo $pages[1];?>.php"/> 
 <!-- here the url is creating but gives error 404 -->
 </head>

 <body>
  <p>Hello, <?php echo $pages[1];?></p><br>
  <a  href="http://www.xyz1.com/kids-english-<?php echo $pages[1];?>.php"><?php echo $pages[2];?></a>

 <!-- here the second url is creating but gives error 404 -->

 </body>
 </html>

Now I want to get the content from database and want to load somefile.php

Here starts my second problem. I create urls by foreach loop but how to load all the content to somefile.php and how will one somefile.php will handle all the different urls and different content created dynamically. I am confused here.

Your suggestions would be welcome. Thank You.

Well.. applications like Wordpress, Shopware and so on are built on a MVC-Design scheme like every other good coded project.

You can go for frameworks like Symfony or build your own routing mechanism.

All in all it's a little bit more tricky as you did mentioned your thoughts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM