Community Forums › Forums › Archived Forums › General Discussion › Create a custom category page
- This topic has 7 replies, 2 voices, and was last updated 10 years, 10 months ago by
Peter.
-
AuthorPosts
-
February 11, 2013 at 3:21 pm #19692
treoguy
MemberI have a category on my website that is for tips. When someone clicks on the menu link, I get a list of tips in chronological order. I would like to customize this page so that I can place some of the more popular tips formatted in specific groups. Below this list would be the standard listing of tips along with pagination to continue through the tips.
Any suggestions on where to start?
February 11, 2013 at 5:22 pm #19721Peter
MemberI'd probably create an extra category like "hot tips" and create a custom page for the tips category. Just before the main loop on the tips category page I would add a custom loop for items in the "hot tips" category. You could also modify the main loop not to display items in the hot tips category so you don't get them appearing in both lists.. if that makes sense..
February 11, 2013 at 5:48 pm #19724treoguy
MemberThanks Peter.
I was thinking to code the top of the page with HTML and then have the category content output below.
Any suggestions on tutorials for creating this custom page and applying it to a category. If I can get my feet wet creating one of these pages, that would be a good start, might give me more ideas on the application.
February 11, 2013 at 6:06 pm #19726Peter
MemberI'm not sure of there are any "official" tutorials on this but there's one from Brian about creating a page to display a single category.. it's not exactly what I meant but could be a good place to start;
February 11, 2013 at 6:26 pm #19735treoguy
MemberI had seen that, but it's not of any help, at least for what I'm hoping to accomplish.
Ultimately, I want to create a custom template that I'll be able to use for a specific category (ie. tips).
At the top, I'll be able to include my custom HTML so I can make it an appealing landing page. Sort of like a table of contents.
So when someone hits the TIPS page, they get:
CUSTOM HTML
--------------------
Regularly updated articles from this category
Pagination to continue to through to other articles in category
I'm sure this has been done, but not sure I'm doing a great job of communicating my goal for the page.
February 11, 2013 at 6:35 pm #19736Peter
MemberI see what you mean..
I'm finishing for the night now but if you haven't got this sorted by tomorrow I will post up some code for you..
Thanks,
Peter
February 11, 2013 at 6:39 pm #19738treoguy
MemberThat would be great. Thanks!
February 12, 2013 at 12:17 pm #19850Peter
MemberThere are lots of ways of doing it but this one might work for you. It used the "genesis_after_endwhile" hook to display the latest posts from a specific category after the page content.
Create a new page template in your child theme folder and drop this code into it, replace "Category Name" with the name of your category;
/* Template Name: Category Name */ add_action( 'genesis_after_endwhile', 'display_custom_category' ); function display_custom_category() { $category_id = get_cat_ID( 'Category Name' ); $category_link = get_category_link( $category_id ); $args = array( 'numberposts' => 5, 'category' => $category_id ); $myposts = get_posts( $args ); if ( $myposts ) { ?> <div class="custom-category"> <h4>Regularly updated articles from Category Name</h4> <ul> <?php foreach ( $myposts as $mypost ) { echo '<li><a href="' . get_permalink( $mypost->ID ) . '" title="' . $mypost->post_title . '">' . $mypost->post_title . '</a></li>'; } ?> </ul> <p><a href="<?php echo esc_url( $category_link ); ?>" title="Category Name">Read more articles in Category Name</a></p> </div><!-- /custom-category --> <?php }// end if } genesis();
When you view a page using this page template you should see the normal page content followed by the latest posts from the category you specified in the template followed by a link to the category page.
It's rough and ready and there's no paging or anything but it might be enough to get you going 🙂
More info on the get_posts function at: http://codex.wordpress.org/Function_Reference/get_posts
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.