Wordpress As Backend Only

寵の児 提交于 2019-12-02 10:53:46

I'm guessing that you want to use the data in Wordpress to display posts without using Wordpress as a frontend? May I ask why you want to do that? Seems like a lot of work and you may able to simple just put your Wordpress install in a blog directory. Then your other code could run in the web root directory.

But if you really want to set up permalinks using Wordpress as a backend, you can do the following.

I'm assuming you're using urls like /blog/blog-post.php?postid=1&type=singlePost

I think I may be wrong about that though...

Anyway, you can just copy the default Wordpress .htaccess rules and put it in a directory named blog

Here is the .htaccess file, but with one change. You need to add RewriteBase /blog/

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress

Now every url in that looks like /blog/my-article or /blog/category/cooking/how-to-cook will be directed to /blog/index.php

This means you'd have to move your code from blog-post.php to /blog/index.php

Now in index.php you can retrieve the actually url using $_SERVER['REQUEST_URI']. So if you visited www.mysite.com/blog/category/cooking/how-to-cook, you'd get /blog/category/cooking/how-to-cook.

Now you can parse the url to get the article name how-to-cook and use it as the id to grab your posts in wp_posts. This will be saved in post_name column.

You dont need to touch htaccess. Just go to settings » permanent links and change default url structure for, lets say, post mame.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!