Community Forums › Forums › Archived Forums › Design Tips and Tricks › Custom Category Pages
Tagged: category, custom category
- This topic has 2 replies, 2 voices, and was last updated 10 years ago by Beneaths.
-
AuthorPosts
-
April 17, 2014 at 7:04 pm #101082BeneathsMember
I've spent a good quality of time trying to find a answer for this and I'm sure if I kept putting more time into it, I could manage to figure it out but I'd love a little help.
I decided I needed a custom category page for my clients website. Currently it is set up where they want the following:
domain/Category1/Category1.2/PostCategory1: Must list out all categories such as Category1.1, Category1.2 etc
Category1.1 (and so on): Must list out all posts that are in the 1.1 category
Each category needs a excerpt above the posts/category links in order to post a description about the categories/posts that are linked.
So far, I decided a custom category.php is needed and I've been struggling since. Any help to point me in the right direction would be great.
I'm at the point that maybe essentially just making it a post may be better but the automation of having the posts automatically added due to it being a category seems nice in the long run instead of having to keep reediting the categories..
April 18, 2014 at 5:58 am #101113Brad DaltonParticipantApril 19, 2014 at 11:50 am #101302BeneathsMemberEnded up brain storming a different way to just push the layout to the client and I'd update him when I figured out a cleaner version.
Parent Category issue:
Decided I'd make category specific ID pages so, category-22.php etc in which would have the following code:
(This would allow for only the main category pages to list off the subcategories)<?php remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'sk_show_subcategories_do_loop' ); /** * Displays a list of linked child categories on category pages */ function sk_show_subcategories_do_loop() { $cat = get_query_var('cat'); $category = get_category ($cat); if ($category->cat_ID) { $children = wp_list_categories("orderby=id&depth=0&hide_empty=0&title_li=&child_of=".$category->cat_ID."&echo=0"); // change depth to 1 if only the top level sub categories should be shown i.e., with children NOT expanded if ($children) { echo $children; } } } genesis();
Subcategory issue:
And to solve the subcategories only listing off the posts in the titles only, I used the following code:
(Subcategories would only display post's titles)add_action( 'pre_get_posts', 'sk_show_titles_only_category_pages' ); /** * Show Linked Titles Only for Posts in Category Pages */ function sk_show_titles_only_category_pages( $query ) { if( $query->is_main_query() && $query->is_category() ) { $query->set( 'orderby', 'title' ); $query->set( 'order', 'ASC' ); // $query->set( 'posts_per_page', '2' ); //* Remove the post info remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); //* Remove the post thumbnail remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); //* Remove the post content remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); remove_action( 'genesis_entry_content', 'genesis_do_post_content_nav', 12 ); remove_action( 'genesis_entry_content', 'genesis_do_post_permalink', 14 ); //* Remove the post meta remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 ); remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 ); remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'sk_custom_loop' ); } } function sk_custom_loop() { //* Use old loop hook structure if not supporting HTML5 if ( ! genesis_html5() ) { genesis_legacy_loop(); return; } if ( have_posts() ) : while ( have_posts() ) : the_post(); do_action( 'genesis_before_entry' ); printf( '<article %s>', genesis_attr( 'entry' ) ); do_action( 'genesis_entry_header' ); do_action( 'genesis_before_entry_content' ); // printf( '<div %s>', genesis_attr( 'entry-content' ) ); do_action( 'genesis_entry_content' ); // echo '</div>'; //* end .entry-content do_action( 'genesis_after_entry_content' ); do_action( 'genesis_entry_footer' ); echo '</article>'; do_action( 'genesis_after_entry' ); endwhile; //* end of one post do_action( 'genesis_after_endwhile' ); else : //* if no posts exist do_action( 'genesis_loop_else' ); endif; //* end loop }
Next step: Try to use conditional tags to display the codes instead of having to have so many custom category id pages. Essentially, just a cleaner layout.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.