WordPress.org

Ready to get started?Download WordPress

Forums

Which file to use for category template? (10 posts)

  1. Jinsan
    Member
    Posted 9 years ago #

    http://codex.wordpress.org/Category_Templates

    Is exactly what I need and have been looking for so thank you to whoever contributed to that entry.

    Now my question is it says create a new category.php - my confusion is what do I or shoudl I copy it from and what should I take out? What I'm trying to get is a result which has a main category (a front page), and then several links to other categories with different styles.

    So going by this new category.php what is it's purpose. You create the id related php files say id 1-6, so what is the purpose of the category.php file and is it needed? More importantly which file would provide the best template for individual categories and does it apply to child categories from that specific parent?

  2. moshu
    Member
    Posted 9 years ago #

    It doesn't say you have to create a category6.php AND a category.php file. It says in which order WP will look for a template to display the category listing. So, suppose you do have a category6.php file it will not look for anything further. If there is no catgeory6.php it will try to look for a generic category.php template, if it finds, will stop looking. If there is no category.php will try to look for archive.php... etc.

    So, you will have to create all the categoryX.php files for your categories that you would like to have a different look. Depending on what theme you are using you can use as a starting point the archive.php or the index.php. Insert/delete the template tags as to achieve the look you want. You will also have to define some div classes in order to be able to add them to your CSS file.

  3. Lorelle
    Member
    Posted 9 years ago #

    I just copied the code from the category.php page (or you can use the archive.php page, or whatever) and pasted it into a text file and called it category-1.php and another for category-2.php and so on, giving me a separate controllable category for every main category in my site.

    Now, I have something like 30 or more categories but most of those are sub categories of the main 8 categories I work with. So I only did categories for the ones I wanted to customize. The rest go to the category.php default since they didn't need the customization.

    Very cool feature!

  4. moshu
    Member
    Posted 9 years ago #

    Hmmm.
    Lorelle, in which theme do you have by default a category.php file?

  5. Lorelle
    Member
    Posted 9 years ago #

    I don't have many themes installed and I'm not going looking, but I found it somewhere when I started working on all this ages ago. Months ago. Use the archive.php file.

  6. moshu
    Member
    Posted 9 years ago #

    I don't need it. I was telling Jinsan how to do it. Then you mentioned that one could start to build the categoryX.php template from the category.php file. In default or classic themes there is no such file.
    That was my point. If one doesn't have a theme with a catgeory.php file s/he cannot start from there... Let's not complicate people's life :)

  7. Jinsan
    Member
    Posted 9 years ago #

    I was about to go down the same route Moshu.

    Lorelle do you have a working example of what you've done? Did you add a seperate style sheet for each category that was customised? How my head is spinning...

  8. Lorelle
    Member
    Posted 9 years ago #

    What is spinning, and no, my example isn't open to the public yet, but will be soon. It's borked right now...hee hee...Gawds I fighting some CSS bugs (actually not MSIE right now!) and the pages are totally....borked. I like saying that word now.

    Anyway, if you look at your archives, they are a form of category. So copy the code from there and paste it into text file and save it as "category-6.php".

    Do two or three of them to test, numbering them accordingly. Then go in and change the text like adding straight HTML:

    <div id="cattext"><p>This is some text that I want in the category 4 page and here is a <a href="link.php">link to something interesting</a> and more html babble.</p></div>

    When you have something different on category-1.php, category-2.php and category-6.php, then upload them and then click on the category links from your index.php and watch them appear.

    If you don't see the specific text you put on the test category, then you might have boo booed. When I first did this, I typed one of them category_6.php instead of the dash. Hey, did I say I was perfect?

    It's so easy I was amazed. It took me a while to really figure it out, and I may clean up the Codex page a bit to make sure it explains this easier, but it is really simple.

  9. Jinsan
    Member
    Posted 9 years ago #

    I have a working structure in my head as I do with a lot of things, it's just a matter of putting it into practice and slowing down and making sure it's all correct.

    It actually seems a very simple process which I will look into soon, I may create the new designs first ready for each category. Thanks

  10. Jinsan
    Member
    Posted 9 years ago #

    Sorry to bump this but it is on topic - now, I've managed to simply use the CSS to create the theme, the template and so on would remain as is. So could I create seperate CSS files for each category and have them called instead of creating seperate php files for each category? As I said the template would much remain the same, only the CSS would be different.

    Actually the template might be slighty different, as the recent reviews would reflect the category topic of the latest reviews. Bugger.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.