admin管理员组

文章数量:1303448

I have set template taxonomy-event_type.php which displays just right on http://localhost:8000/types/<type_name>/.

What I need now is to:

  • either redirect when user lands on http://localhost:8000 to this page,
  • or use this template with (what wouldn't be greatest, as i'm checking the url and setting navigation items as active according to the url)

So something like (PSEUDOCODE):

if is_home(): 
   redirect('types/type1')

or

use_template('taxonomy-event_type','type1');

is it possible?

I have set template taxonomy-event_type.php which displays just right on http://localhost:8000/types/<type_name>/.

What I need now is to:

  • either redirect when user lands on http://localhost:8000 to this page,
  • or use this template with (what wouldn't be greatest, as i'm checking the url and setting navigation items as active according to the url)

So something like (PSEUDOCODE):

if is_home(): 
   redirect('types/type1')

or

use_template('taxonomy-event_type','type1');

is it possible?

Share Improve this question edited Mar 20, 2021 at 21:40 MCFreddie777 asked Mar 20, 2021 at 21:19 MCFreddie777MCFreddie777 1012 bronze badges 1
  • Note that the template doesn't determine the posts that get shown, so if you did load that template on the homepage, it would be the same posts you saw on the homepage before but in that template, not the posts from a particular term. URL creates query -> query fetches posts -> query + posts determines template to load – Tom J Nowell Commented Mar 20, 2021 at 23:26
Add a comment  | 

1 Answer 1

Reset to default 0

Found a solution:

// redirect on homepage to taxonomy
add_action("template_redirect", function() {
    if (is_front_page()) {
        return wp_redirect(get_term_link('type1', 'event_type'));
    }
});

本文标签: redirectHow to show taxonomy on front page