Support » Plugins » Hacks » Need to associate categories to a page

  • I have the following sitemap:

    Home (Page)
    About (Page)
    – Who We Are (Page)
    – What We Do (Page)
    Media (Page)
    – News (Category)
    – Videos (Category)

    I set up the menu in the above manner and its working fine.

    However, facing problems with the Breadcrumbs (using Breadcrumb NavXT).

    1. Whenever I go to Media > News, the breadcrumbs is showing Home > News (instead of Media > News), because they are unrelated.

    2. I have a plugin that shows the subpages of the current page using a simple shortcode. For example, when I go to the About page, it’ll show “Who We Are” and “What We Do” as its subpages in the form of a list. However, this is not working when I go to the “Media” page because everything under Media in the menu aren’t really associated with the “Media” page.

    I couldn’t find any way of associating both the categories “News” and “Video” to the Page “Media”. Is there any way I can do so so that the two problems I mentioned above can be resolved?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz


    You can associate any taxonomy with any post type, including categories with pages with register_taxonomy_for_object_type(). The code for this can be placed on either functions.php of a child theme or in a site specific plugin established to contain little hacks like this. This is the code you would use:

    add_action('init', 'mb_cat2page', 15 );
    function mb_cat2page() {
       register_taxonomy_for_object_type( 'category', 'page' );

    The page edit form should now have a metabox for assigning categories, check the screen options if you do not see it.

    I’m not entirely sure this will solve your problems, but it’s easy enough to try and see since you have the code to make it possible.

    A more straight forward logical approach would be to make a page template out of the archive template used for news and video, then create specific pages that list these items, making those pages children of the Media page. The new category association can play into this, but it probably could be done without as well.

    Hi bcworkz,

    Making the page template out of the archive template does seem like a logical approach, however, once you get into a post of a certain category, the breadcrumbs and permalinks no longer appear correct. The posts cannot be children of the Media Page. How do I work around this problem?

    Unfortunately register_taxonomy_for_object_type isn’t solving the problem either.

    The Telenor Wesbite website (powered by WordPress) somehow managed to do it:

    This is their Media Page:

    These seem to be their Categories:

    Notice how both articles and press releases come under media in their permalinks.

    This is a post under articles:

    Notice how the post also appears under media/articles/2014

    I am looking for a solution exactly like the telenor site.

    Moderator bcworkz


    My apologies, I didn’t fully understand where you were going with this. Other than proof that a particular site organization is possible, the telenor site is unfortunately not very useful unless the underlying code is available.

    It sounds like you are looking for a completely hierarchical organization. AFAIK there is simply no way to make posts hierarchical. Your best approach is probably to create a custom post type for your posts that is hierarchical. It shouldn’t be too hard to convert existing posts to the new CPT once the scheme has been fully tested. Assigning the proper hierarchy could be tricky or easy, it’s hard to say without knowing how your data is setup.

    The other possibility is to apply a hierarchical taxonomy to posts, which can be done with categories (which is where you are obviously trying to go) or a custom taxonomy. The problem you run into with either approach is your breadcrumb plugin may not be able to adapt, requiring either modification or a different approach.

    In a similar vein, the permalinks may not form the way you want, requiring a plugin or custom code. The question isn’t so much if this is possible, it’s can you find the right plugins or are you able to generate the needed code, either by yourself or by hire.

    I’m not offering to do anything for hire here, and I do not offer any significant code for free, but I am willing to advise within the limits of this forum and my own knowledge.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Need to associate categories to a page’ is closed to new replies.