Page template with all categories
-
This has been really frustrating. For two days now, I′ve been trying to understand how to make the simplest, stupid page template with links to all categories on it (like a directory). I know I have to make a custom template starting with
<?php /** * Template Name: EXAMPLE NAME * * @package WordPress * @subpackage Twenty_Fourteen * @since Twenty Fourteen 1.0 */
Then I found from that I need to add this:
<?php $categories = get_categories( array( 'orderby' => 'name', 'order' => 'ASC' ) ); foreach( $categories as $category ) { $category_link = sprintf( '<a href="%1$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>'; }
I know I′m missing something because I′m getting errors.
I will not become php expert just for this and will not go through the entire codex just so I can display 5 categories on one page. Forgive my frustration and anger but I really think wp shouldn′t be that “enigmatic” for beginners.
If anybody has done this or has the knowledge and is willing to share, it would be highly appreciated.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Page template with all categories’ is closed to new replies.