WordPress.org

Forums

[resolved] category_template confusion (9 posts)

  1. dwm376s
    Member
    Posted 8 years ago #

    So I have been reading all about Category templates in the codex, in order to create a category template for one of my categories. I understand the basics such as how the Template Hierarchies work etc. Just not sure where to start to get the end result I am looking for.

    I want to create a category template for categoy #X. I want the posts in this category to follow the same CSS as the posts in any other category. I want this category excluded from the main list of categories.

    Currently posts are displayed in their entirety and have a date stamp, and are listed in reverse chronological order. I want the posts in this category to be listed alphabetically, by title only, and without a date stamp.

    I am certainly no expert at pHp, I just need a nudge in the right direction to get started.

  2. Kafkaesqui

    Posted 8 years ago #

    Boy, you want a lot... :) Let's try and take it one at a time:

    I want to create a category template for categoy #X.

    Easy:
    http://codex.wordpress.org/Category_Templates#What_Template_Displays_a_Particular_Category
    (Google cache if Codex is down)

    To the point: if you create a category-10.php template, this is the template which will be used when category #10 is queried, while posts in that category will continue to use the same template as other posts.

    I want this category excluded from the main list of categories.

    Again, easy:
    http://codex.wordpress.org/Template_Tags/wp_list_cats
    (Google cache if Codex is down)

    Look for the info on the 'exclude' option.

    I want the posts in this category to be listed alphabetically, by title only, and without a date stamp.

    Issues of layout can be handled through use of an individual category template (see above). You only need edit the template down to the elements you want displayed. For managing sort order, this plugin will help provide that:

    http://mattread.com/projects/wp-plugins/custom-query-string-plugin/

  3. dwm376s
    Member
    Posted 8 years ago #

    plug in is cool. Pretty easy to use.

    About the exclude. I want to exclude category 12 from the list. So where do I insert the pHp code:

    <ul>
    <?php wp_list_cats('sort_column=name&optioncount=1&exclude=12); ?>
    </ul>

    I would assume in the category.php file. However, my theme doesn't have a category.php file. So what file do I insert this in?

  4. moshu
    Member
    Posted 8 years ago #

    Since I assume you meant to exclude that category from being listing in the sidebar. So, you'd edit the sidebar.php.

    If that wasn't your intention - then re-phrase your wishlist: both Kaf and I understood exactly what he told you to do.

  5. dwm376s
    Member
    Posted 8 years ago #

    thanks Moshu,

    I edited sidebar.php, and go the category to be excluded from the list. By using the following code:

    wp_list_cats('sort_column=name&exclude=12');

    Worked well after I played with it a bit. So my next question for you guys is how do I keep posts in that category from appearing on the main blog page?

    I am guessing that I can simply use the same snippet of code above in the index.php file???

  6. moshu
    Member
    Posted 8 years ago #

    Nope.
    The answer - as so often - is: plugin. http://ryowebsite.com/?p=46

  7. dwm376s
    Member
    Posted 8 years ago #

    very nice!! thank you. Actually this plugin solves to of the things I wanted at once, excluding the category from the sidebar as well as main blog. Thus I can disable the Custom Query String plugin.

    Thank you both for the help. There are a few more things I want to do with categories, but gonna give it a go on my own and see what happens.

  8. dwm376s
    Member
    Posted 8 years ago #

    well gave it a crack...and managed to create a catergory-#.php files that works!!! Still doesn't look exactly the way I want, but functions perfectly. I can experiment with the code to get the look I am after. Thanks again.

  9. dwm376s
    Member
    Posted 8 years ago #

    another question on category-#.php templates:

    I created category-12.php and it formats the category archive just how I intended. I have another category archive that I want to be formatted in the same way, so I created an exact duplicate of category-12.php and renamed it accordingly (category-13.php).

    However, it doesn't display the category 13 archive in the same manner. Any ideas....I am stumped?

Topic Closed

This topic has been closed to new replies.

About this Topic