Displaying info on Category Pages differently

Community Forums Forums General Discussion Displaying info on Category Pages differently

This topic is: not resolved

This topic contains 4 replies, has 3 voices, and was last updated by  Summer 1 year, 1 month ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #63117

    slydawgg
    Participant
    Post count: 20

    I was curious if there was any hooks or functions in Genesis that I am overlooking to display category pages differently based on the category… I am sure there is a way to do it using WordPress, but I haven’t been able to make it work either b/c I am probably over-thinking it.
    I’ve created a category.php template to display my Posts based on whatever their category is.

    What I want to do is this:

    If (all categories)
    show titles of post for all categories
    if (only categoryA selected and showing)
    filter to show titles for categoryA only
    if (only categoryB selected and showing)
    filter to show titles for categoryB only
    and so on…

    ====================
    Currently I have something like this, so I am looking for a better and more efficient way to do it.

    <?php if ( is_category('20') ) {
    	echo '<h1>';
    	printf( __( 'This is Category A', 'genesis' ), home_url() );
    	echo '</h1>';
    }
    ?>
    
    <?php if ( is_category('25') ) {
    	echo '<h1>';
    	printf( __( 'This is Category B', 'genesis' ), home_url() );
    	echo '</h1>';
    }
    ?>
    

    ====================
    This doesn’t seem very efficent, especially if you have 10 or more categories.
    I know if I do wp_get_archives() I can see all posts but I am not sure the best way to filter based on Category; but I don’t think there is a parameter to filter what I am trying to do

    Any suggestions?

    #63120

    Sridhar Katakam
    Participant
    Post count: 1048
    #63172

    slydawgg
    Participant
    Post count: 20

    Sridhar,
    This is very close to what I am trying to do because it does display the category name, but I still need it to do one thing.

    I need it to filter the Posts found within those categories; looks like I didn’t say that in my above code.

    So…

    if (all categories)
    show all Posts by displaying the title of each post, as a list.
    if(CategoryA)
    show only CategoryA posts as a list)
    if(CategoryB)
    show only CategoryB posts as a list)
    etc…

    Let’s say my Categories are Apples and Grapes; I would want to have a page that filters out:

    This is the Apples Category (title of Category)
    >Red Apples (title of Post)
    >Green Apples (title of Post)
    >Apple Pie (title of Post)
    >etc…

    This is the Grapes Category (title of Category)
    >White Grapes (title of Post)
    >Red Grapes (title of Post)
    >Wine Grapes (title of Post)
    >etc…

    The is ALL Categories (displaying all Categories on one page)
    >Red Apples (title of Post)
    >Green Apples (title of Post)
    >Apple Pie (title of Post)
    >White Grapes (title of Post)
    >Red Grapes (title of Post)
    >Wine Grapes (title of Post)

    I hope this makes sense, and you can assist

    #63202

    Sridhar Katakam
    Participant
    Post count: 1048
    #63218

    Summer
    Participant
    Post count: 1105

    You could make separate templates based on each category you want to customize… that’s the “WordPress” way, anyway :)

    So, you’d have separate templates, say category-grapes.php, category-apples.php, and the templates should just pull the category as the title, and you wouldn’t have to do anything special with conditionals. Then just leave category.php for everything & the kitchen sink, and you should be good.

    See this to start: http://codex.wordpress.org/Template_Hierarchy#Category_display


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

You must be logged in to reply to this topic.