Site logo

Archived topic

Add categories to Pages

18 replies · Started by Isaac on January 2, 2019

Viewing posts 1–15 of 19

Hi,

I'm trying to use as few plugins as possible on my site.

Is there any way I can add categories to pages using GeneratePress out of the box? (I've searched docs)

I know there is a bazzilion plugins that will do this, but I'm trying to keep Plugin use to a bare minimum, so that my site remains lightweight.

thanks

Isaac, this has worked for me:

Using the Code Snippets plugin (which I already use), I added this code:

function add_taxonomies_to_pages() {
 register_taxonomy_for_object_type( 'post_tag', 'page' );
 register_taxonomy_for_object_type( 'category', 'page' );
 }
add_action( 'init', 'add_taxonomies_to_pages' );
 if ( ! is_admin() ) {
 add_action( 'pre_get_posts', 'category_and_tag_archives' );
 
 }
function category_and_tag_archives( $wp_query ) {
$my_post_array = array('post','page');
 
 if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
 $wp_query->set( 'post_type', $my_post_array );
 
 if ( $wp_query->get( 'tag' ) )
 $wp_query->set( 'post_type', $my_post_array );
}

Once added to Code Snippets, enable. That's it. Categories will show for pages, no different to posts.

I originally tried to add the code using GP > Elements, but couldn't figure it out. But Code Snippets works great.

Thanks Andre!

Thanks Andre.

In the end I just went with a plugin.

The plugin was really small, like 2.1KB so wouldn't have bloated out my
site and it was simple.

Cheers

Isaac, which plugin did you go with?

Hello

I'm also looking for a lightweight way to use post categories for pages too. I've added the relevant php to code snippets as mentioned above.

It's working but the secondary navigation does not recognise the active category on a page. What am I missing?

Does the primary navigation recognize it? If not, I assume WordPress is doing something else internally to make that connection. Have you tried the plugin mentioned above?

Hi there,

can you share a link to your site ? You may want to start a new topic where you can share the link privately using the Site URL field provided.

OK thanks, I'll start a new topic

Looking for same kind of feature: using categories for pages, just like they can be used for blog posts and Woo products.

But more important: the categories need to be used in the permalink structure too - just as with posts and products.

For example, if the categories are:

= wall art
== living room
=== canvas print (in this example the checked category)
=== fine art print
=== etc

Then the slug need to become: /wall-art/living-room/canvas-print/page-title

Does anyone know if a plugin like Add categories to pages makes that possible?

Thnx for the reply! :-)

Yes, I now about the parent child structure, creating a permalink structure/hierarchy.

Wondering why WP created such a thing for posts, but not for pages...

This archived topic is closed to new replies.