Create a custom category page

Community Forums Forums General Discussion Create a custom category page

This topic is: not resolved

This topic contains 7 replies, has 2 voices, and was last updated by  Peter 1 year, 7 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #19692

    treoguy
    Participant
    Post count: 24

    I 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?

    #19721

    Peter
    Participant
    Post count: 76

    I’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..


    Website: petercoughlin.com
    Twitter: petercoughlin

    #19724

    treoguy
    Participant
    Post count: 24

    Thanks 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.

    #19726

    Peter
    Participant
    Post count: 76

    I’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;

    http://www.briangardner.com/blog-page-single-category/


    Website: petercoughlin.com
    Twitter: petercoughlin

    #19735

    treoguy
    Participant
    Post count: 24

    I 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.

    #19736

    Peter
    Participant
    Post count: 76

    I 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


    Website: petercoughlin.com
    Twitter: petercoughlin

    #19738

    treoguy
    Participant
    Post count: 24

    That would be great. Thanks!

    #19850

    Peter
    Participant
    Post count: 76

    There 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;

    [php]/*
    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();[/php]

    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


    Website: petercoughlin.com
    Twitter: petercoughlin

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.