0
votes

I'm new to Wordpress and I can't figure out how one can create a general custom theme page for all categories in Wordpress. I've seen many tutorials for how to create custom theme pages for each category but none for how to create a general one for all category links.

How is that achieved? Thanks

1
Are you talking about posts or pages?Daniel
@Daniel Im talking of custom theme page for all categoriesStanley Ngumo

1 Answers

0
votes

For the sake of simplicity, I'm going to assume you're referring to all categories of the post_type "post" e.g. "Posts" on the admin menu.

You can create a custom function or use this code in a page to list all categories get_categories:

$categories = get_categories( array(
    'orderby' => 'name',
    'order'   => 'ASC'
) );

foreach( $categories as $category ) {
    $category_link = sprintf( 
        '<a href="%1$s" alt="%2$s">%3$s</a>',
        esc_url( get_category_link( $category->term_id ) ),
        esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
        esc_html( $category->name )
    );

    echo '<p>' . sprintf( esc_html__( 'Category: %s', 'textdomain' ), $category_link ) . '</p> ';
    echo '<p>' . sprintf( esc_html__( 'Description: %s', 'textdomain' ), $category->description ) . '</p>';
    echo '<p>' . sprintf( esc_html__( 'Post Count: %s', 'textdomain' ), $category->count ) . '</p>';
}

You can obviously adjust the output as you see fit.

Source