简体   繁体   中英

How to get the Following URL Structure in WordPress?

I have a

  • Custom Post Type - Awards (slug = awards)
  • Custom Taxonomy - Award Giver (awards-giver) (eg Oscars, Golden Globe, etc)
  • Custon Taxonomy - Awards Types (award-type) (eg Best Actor, Best Film, etc)
  • Custom Taxonomy - Award Year (award-year)

Now I want to dynamically have pages on my site with the following URL Structure

example.com/awards/oscars/year/2011

example.com/awards/oscars/best-actor/ (which will list all the winners of best actor award till now of all years)

I need to get these url structures working in WordPress. Any Advice?

Thanks in Advance :)

Example for: example.com/awards/oscars/year/2011

This might help you. Put below code into your functions.php file:

function custom_rewrite_basic() {
    add_rewrite_rule('^awards/([A-Za-z0-9._-]+)/year/([0-9]+)/?', 'your_actual_working_file_url.php?award_type_slug=$matches[0]&year=$matches[3]', 'top');
}
add_action('init', 'custom_rewrite_basic');

RewriteRule ^awards/([A-Za-z0-9._-]+)/year/([0-9]+)/?$  your_actual_working_file_url.php?award_type_slug=$1&year=$2

Make sure you put your actual working file url/path in above code as per your custom template file name or default template file name.

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