Support » Plugins and Hacks » Hacks » Custom taxonomy as homepage

  • Is there a way to show a certain custom taxonomy as the homepage of my website? Just like you would choose a static page or the blog as the homepage in the settings? This can be a plugin…

    I don’t want to hardcode the custom taxonomy in my php files, as the shown taxonomy will vary from time to time.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could still easily add it to your theme and have an option to select the category from a settings page for when it changes. It could also be a plugin, but either way you’ll need a settings page to use the output of get_object_taxonomies as your options:

    $custom_taxonomies_array = get_object_taxonomies('custom_post_slug');

    You can then modify the instuctions for changing the post type that’s used on the front page for categories, and grab the option you’ve saved on your settings page and insert it as follows into your functions.php or elsewhere in your plugin if you don’t want it as a part of your theme:

    // Show category from option on home page
    add_action('pre_get_posts', 'change_front_page_main_query_to_custom_taxonomy');
    
    function change_front_page_main_query_to_custom_taxonomy($query) {
    	if (is_home() && $query->is_main_query())
    		$query->set('cat', get_option('option_from_dropdown_on_settings_page'));
    	return $query;
    }

    Hi maxxsnake,

    Thanks for your reply. Though I’m afraid I’ll need some more directions. How do you create the “settings page” you’re talking about? Where do I put this code:

    $custom_taxonomies_array =
    get_object_taxonomies('custom_post_slug');

    I’ve added the other code to my functions.php as the theme won’t change that soon. But I guess that won’t work if I don’t have the previous code somewhere in my site.

    Hi maxxsnake,

    Can you help me out here? Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom taxonomy as homepage’ is closed to new replies.