29

I have generated pages using a custom template by creating a php file in my theme directory something like :

<?php
 *
 * Template Name: Contact Page
 */
 ?>
 <html ..... </html>

and then adding a new page on the dashboard selecting this new template

How can i now associate tags and categories to each pages ? Is creating posts instead of pages the only solution?

3
  • Can you elaborate on what you mean by associate tags and categories to each page? Do you mean bring posts in from specific categories/tags and display them on this page or have this page be part of a category/tag? Jan 14, 2013 at 20:13
  • This should be closed. It's a duplicate of this: stackoverflow.com/questions/14324026/… Jan 14, 2013 at 20:37
  • @Spencer Cameron thanx for your reply: i mean "have this page be part of a category/tag?" ! and no, the 2questions are not exactly the same...in this one i am asking if it s possible to add catégories from a page ( and not a post ) generated by the dashboard using or not a custom template
    – Matoeil
    Jan 18, 2013 at 16:40

5 Answers 5

80

Even better is to add to functions.php in your theme folder:

function myplugin_settings() {  
    // Add tag metabox to page
    register_taxonomy_for_object_type('post_tag', 'page'); 
    // Add category metabox to page
    register_taxonomy_for_object_type('category', 'page');  
}
 // Add to the admin_init hook of your theme functions.php file 
add_action( 'init', 'myplugin_settings' );
4
  • 3
    It would be better to use the init action and not the admin_init action. When using admin_init action, the categories/tags menu will not appear under pages in the admin_menu. Mar 13, 2014 at 12:03
  • 2
    It's not just better -- it only works if you set it to init hook. Don't use admin_init hook
    – FooBar
    Mar 21, 2015 at 15:16
  • 2
    Fantastic! A script solution and not another recommended plugin. Jul 16, 2016 at 11:27
  • 2
    Truly useful, I'm a php programmer with zero WP experience and this helped me a lot, adding another plugin was pointless..
    – cdsaenz
    Oct 26, 2019 at 0:02
16

Tried using the accepted answer but for some reason it only shows the Post types and none of the Pages shows in the category page. E.g. /category/entertainment/

To fix that, I have to do this:

// add tag and category support to pages
function tags_categories_support_all() {
  register_taxonomy_for_object_type('post_tag', 'page');
  register_taxonomy_for_object_type('category', 'page');  
}

// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
  if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
  if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}

// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');
1
  • It works but the breadcrumb is missing the categories, how to fix them? Dec 1, 2021 at 12:51
1

Try this:

add_action( 'init', 'wpse34528_add_page_cats' );
function wpse34528_add_page_cats(){
    register_taxonomy_for_object_type('post_tag', 'page');
    register_taxonomy_for_object_type('category', 'page'); 
}
1
1

Not at all helpful to say 'download plugin' for beginners who are most likely not going to have downloaded wordpress and are therefore not able to install said plugin. Here is some short code for those like me that have been scouring the web for something that actually works on regular pages with regular accounts - ie you're not a developer.

First, make sure you have your pages in your menu set up properly. YOU DO NOT NEED TO MAKE YOUR PAGES 'Categories' or 'Tags'! This wouldn't give you actual pages to then go and edit, so if you are wanting to add sliders, text, an intro, or anything for that matter, you wouldn't be able to.

Then go to WP Admin > Pages Select a page to edit and go to the text editor instead of visual editor (far right hand side tab)

Then past the following short code:

[display-posts category="hair,makeup,reviews,beauty" posts_per_page="10" include_date="true" text-decoration: none date_format="F j, Y" order="DESC" include_excerpt="true" wrapper="div" image_size="large"]
&lt;

(The shortcode collects all the posts that you have assigned certain categories in your blog posts i.e. mine was hair and beauty. So obviously change yours to ones that are appropriate. It then allocates how many posts (mine was 10), the date (in descending order,) with a large image and an excerpt of the post)

-1

this plugin sorted me out :

http://wordpress.org/extend/plugins/add-tags-and-category-to-page/

with the standard instructions :

Upload the plugin files to the /wp-content/plugins/ directory
Activate the plugin through the 'Plugins' menu in WordPress
Use the setting page of the plugin from Settings > Add Tags And Category For Page.
1
  • 1
    Note that this plugin is currently incompatible with WP > 3.6.1.
    – isherwood
    Jan 27, 2014 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.