使用我的自定义CMS创建页面

I have started creating a CMS today for my own personal use, for management purporses and also to teach myself a few things.

I have a section in my admin area where I can create/update/delete pages or posts which works great.

My question is how do I generate pages, and URL's from the information I have stored in my database?

Let's say for example my table "posts" has a few rows which contain "post_title", "post_content", "post_slug", etc. How do I generate a page from this information in my database (because it's obviously not creating pages based on PHP files), so I would have http://mywebsite.com/cool-new-post-slug.php (then I can get content by ID, etc)?

If someone can point me in the right direction that would be great. Thanks for your answer.

If I understand your question correctly, you'll need to retrieve all the slugs from the database first, then use them to construct your url.

Assuming you're using mysqli:

$query = "SELECT post_slug,post_title FROM posts";
$posts = mysqli_query($con,$query);
while($post = mysqli_fetch_assoc($posts)){

    echo "<a href=\"single.php?slug=" . $post["post_slug"] . "\">";
    echo $post["post_title"];
    echo "</a><br/>";

}

mysqli_free_result($posts);

Then on single.php you'll use the GET variable post_slug to retrieve your data.

in your .htaccess file you can use mod_rewrite to get pretty URLS as follows:

RewriteEngine On
RewriteBase /
RewriteRule posts/(.+?)/?$ single.php?slug=$1

this would show the url http://mywebsite.com/posts/cool-new-post/ your browser, but what it will really be accessing is single.php?slug=cool-new-post