WordPress.org

Ready to get started?Download WordPress

Forums

Can each category page have its own look? (20 posts)

  1. joeking
    Member
    Posted 9 years ago #

    Okay, I've almost given up looking for an answer to this, but thought I'd try to explain myself better one more time.

    At the moment, my category pages look like my index page.

    But what I would like to do is have different content in each category sidebar for example and a different header image.

    Is what I'd like to do possible? And by that I mean possible for a newbie? :-)

    And if so where do I start? I don't mind spending hours playing around to see what works, but need a few pointers. Or for someone to say that I can't do that so go do something else instead.

  2. paulh
    Member
    Posted 9 years ago #

    It's possible. You could play a few tricks with CSS to replace the header image based on the category.

    Likewise with the sidebar, using custom CSS for each category, you could hide elements and display others.

    You'll need to hack your template to add a "<category>.css", where WP will be filling in the <category> part.

  3. jberglund
    Member
    Posted 9 years ago #

    joeking: I had the same question. Take a look at this thread and see if it helps: http://wordpress.org/support/topic.php?id=20048

    I still haven't had my 'permalinks' question answered, so I haven't started implementing it, yet.

  4. Nick Momrik
    Member
    Posted 9 years ago #

    From looking through the code the other I seem to remember seeing that you can have a template in your theme for each category...such as category-***.php

  5. joeking
    Member
    Posted 9 years ago #

    Many thanks for everyone's help.

    I'm going to see what I can do and will let you know how I get on. Here's hoping :-)

  6. joeking
    Member
    Posted 9 years ago #

    Okay, I've tried creating a very simple category-1.php file with just three lines:

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    This works because when I go through to category 1 I see just the header, sidebar and footer. So far so good.

    But I then created headercat1.php so that category 1 would have its own header.

    I changed category-1.php to:

    <?php get_headercat1(); ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    And the page doesn't show :-(

    Instead I get an error message saying :

    Fatal error: Call to undefined function: get_headercat1() in . . .

    Any ideas where I'm going wrong here?

  7. Kafkaesqui

    Posted 9 years ago #

    <?php get_header(); ?>

    Is a "tag" for WordPress' PHP function get_header(), which does little more than provide an include to the header.php file of the current theme.

    <?php get_headercat1(); ?>

    Is a tag for a non-existent function, get_headercat1(), unless you've actually written it. Use instead the underlying functionality of the get_* include tags to include your new template:

    <?php load_template( TEMPLATEPATH . '/headercat1.php'); ?>

  8. joeking
    Member
    Posted 9 years ago #

    Thanks very much Kafkaesqui.

    I assume I've to enter the template path where you've put TEMPLATEPATH in the code.

    My headercat1.php has been uploaded to the same theme folder as the category-1.php file.

    It's full path is:

    public_html/wordpress/wp-content/themes/benevolence/headercat1.php

    I've tried variations of this without success.

    Am I doing the right thing?

  9. superkim
    Member
    Posted 9 years ago #

    Have You tried just doing it literally? I'd assume the big letters means a code that wp uses, the templatepath being known otherwise by wp, eg when you select the theme.

    try it the way it stands!

  10. Kafkaesqui

    Posted 9 years ago #

    "I assume I've to enter the template path where you've put TEMPLATEPATH in the code."

    You can, but TEMPLATEPATH is defined as a constant (a *permanent* PHP variable) in WordPress; so when you use it in your code, it will insert the full path to the current template/theme directory.

  11. joeking
    Member
    Posted 9 years ago #

    Kaf - Doh! I'm so stupid. It just seemed too obvious to copy the code you gave me.

    Superkim and Kaf - many thanks for your help!

    I am now going to add other things to the page but am now on my way to creating individual category pages.

    Thanks to everyone who has helped me :-)

  12. joeking
    Member
    Posted 9 years ago #

    Okay my basic category-1.php has just this code:

    <?php load_template( TEMPLATEPATH . '/headercat1.php'); ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Now I need to have it display the posts for category 1, but don't know what code to add for this to happen

    Also if there are say 20 posts in category 1 will the category 1 page display all 20 posts? What happens if you have 200? And if it doesn't display them all, where do people find them?

  13. Lorelle
    Member
    Posted 9 years ago #

    Okay, I had help from MDAWaffe who saved my life with this one. Check out the discussion at http://wordpress.org/support/topic.php?id=22567 and this is brilliant. Totally brilliant and amazingly easy.

    Basically, you can take the archives.php (unless you already have a category.php from your theme author) and make a copy of it and call it "category-1.php". You can add your own text, do your own thing to it and it is the category page for category one. If you have a category 24 it would be "category-24.php" and you can do your own thing...etc.

    When WordPress looks for the category page when you click a category, by default it looks for (if I remember right):

    1. category-X.php
    2. category.php
    3. index.php

    Read the discussion then look for his article on the Codex when it is back up running as it goes into a little more detail. It's brilliant if you are serious about having customized categories that still use all the loverlies of the WordPress Loop.

  14. Rob Poitras
    Member
    Posted 9 years ago #

    hey joe, you get this to work?

    i want to do the same thing pretty much but I cant get it to work.

  15. joeking
    Member
    Posted 9 years ago #

    Bob - yes to a degree I have but am having a few problems with content. The actual creation of category-1.php, etc., is very easy. WordPress just picks up on it instantly and brings up the correct posts without you having to do anything else.

    My problem is I want a third column and have resorted to tables (I know - but I don't understand enough CSS yet) to do this. The correct content still displays but the style sheet is gone so headers, text, etc., are all the same size and font.

    But if you are not wanting to make major changes, just copy a file such as index.php and rename it category-1.php. Make a change, upload it and WordPress will display it as the new category 1 page.

  16. dhazard
    Member
    Posted 8 years ago #

    ok, here is my problem - i got the category pages to work:

    http://www.ucc.org/information/?cat=1
    http://www.ucc.org/information/?cat=2
    http://www.ucc.org/information/?cat=3

    but when i click to one of the full stories (in this case in the third category):

    http://www.ucc.org/information/?p=3#more-3

    I lose the formatting of the category - why is that? and if another template applies here can i create files similar to category-1,2,3.php. It looks like archive.php may be controlling this so can I create archive-1.php, archive-2.pho, etc. This seems a long way around solution - why wouldnt the category templates cover everything posted within them?

  17. kingjeffrey
    Member
    Posted 8 years ago #

    Here is another relevant thread ( http://wordpress.org/support/topic/31344 ) about how to add new get_XXXXX() functions.

  18. skippy
    Member
    Posted 8 years ago #

    These two links might be helpful:
    chrisjdavis.org/2005/05/26/secrets-of-wp-theming-part-1/
    chrisjdavis.org/2005/06/02/secrets-pt-2

  19. moshu
    Member
    Posted 8 years ago #

    @dhazard,
    The last link's display is controlled by the single.php template. PLease, follow this thread to see different solutions to have the single posts displayed as you want.
    http://wordpress.org/support/topic/27073

    And this one is a solution for different category templates
    http://wordpress.org/support/topic.php?id=29434#post-173621
    though I guess you've got that :)

  20. techwench
    Member
    Posted 8 years ago #

    I have this working on my site now, in just the 3 wordpress-related categories. What I did was setup 4 different header files - one for each of the WP categories, and a main header.

    This is what I used in my single.php instead of get_header()

    <?php
    $post = $wp_query->post;
    if ( in_category('2') ) {
    include(TEMPLATEPATH . '/header-wp.php');
    } elseif ( in_category('3') ) {
    include(TEMPLATEPATH . '/header-themes.php');
    } elseif ( in_category('4') ) {
    include(TEMPLATEPATH . '/header-plugins.php');
    } else {
    include(TEMPLATEPATH . '/header.php');
    }

    get_sidebar();
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.