简体   繁体   中英

How can I display dynamic content based on URL slug on a custom WordPress page?

I have a custom page named locations and i want the URL to load like this:

/locations/california
/locations/nevada
etc..

and upon each page load of the given URL as above content is loaded based on it. So for example if California is loaded specific information to california would be loaded. How would I go about doing this in WordPress? I tried visiting /locations/california and I get a 404 so I guess WordPress is looking for the permalink /locations/california

What do you mean by "custom page"?

You could just add a custom post type "locations" through which you would organize the states/cities/whatever. By default Wordpress will automatically use the post type name as a slug. See http://codex.wordpress.org/Post_Types

For the overview page (/locations/) Wordpress will search for archive-locations.php (if you initialized the CPT with an archive). For the single page (/locations/whatever) it would be single-locations.php.

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