WordPress.org

Ready to get started?Download WordPress

Forums

Categories and Static Pages (19 posts)

  1. Lorelle
    Member
    Posted 9 years ago #

    This is a question different from the ones asking to put pages under categories. I understand that the v1.5 "pages" concept is to create static pages.

    A lot of people are using Pages to distinquish their different categories. This applies to me, too. But I'm confused.

    If someone clicks on a link to, say, the Archives Page (physical page representing the category: archives), and then they click on the category in the sidebar "archives" or from one of the category listings in a post (Filed under: Archives), which page do they go to?

    I want to keep the categories on their own pages since there is static information related to each category, which makes the static pages wonderful. But what if someone bypasses the static page by using the category link?

    See my confusion? How can we clean this up?

  2. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    If someone clicks a Category link (from anywhere), they will be taken to a list of Posts belonging to that Category.

    If someone clicks a Page link (from anywhere), they will be taken to that Page. Again, here I mean "WordPress Page" - the "static" (another misnomer) Post-like feature in 1.5

    If you don't want people to follow the Category links, don't give them the option:

    Just list the Pages on your sidebar (using wp_list_pages). Don't list the categories (take out wp_list_cats or whatever tag is being used). That way no one can ever "bypass" your static pages.

  3. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    I'm not clear on what you're trying to do, though, when you say [you] "are using Pages to distinquish their different categories".

    If you want to organize or style your site differently, or display different static content when a particular category is displayed, you might try nixing the Page idea and implement the following.

    CASE 1: You want some text displayed before all the posts when a user follows any any Category link (i.e. the same text for all categories).

    Create in your theme directory a file called category.php. Actually, you might want to copy archive.php or index.php or page.php over to this new category.php so you don't have to write as much code, just alter it instead.

    At any rate, this is the template that WordPress will reference whenever a Category link is followed (see next post for a detailed description on what templates WordPress tries to use in this situation). Above The Loop, put in <div id="sticky-snip">This is some text that will always display when any Category link is followed</div>

    Booyah.

    CASE 2: You want different text to display above the list of Posts from the Category depending on what Category the viewer is looking at. Example: Display "These posts are all about cheese" for the "Cheese" category, and "I am not wearing any pants" for the "Shorts" Category, and "The following is a list of posts about some particular topic" for ALL OTHER CATEGORIES.

    Rather than making a template with lots of if statements, WordPress allows you to do the following nifty trick.

    Create category.php as above. Put
    <div id="sticky-snip">The following is a list of posts about some particular topic</div>
    above The Loop.

    Figure out the Category ID of the Cheese Category. Say it's 6. Create category-6.php as above. Put in
    <div id="sticky-snip">These posts are all about cheese</div>
    above the Loop.

    Figure out the Category ID of the Shorts Category. Say it's 19. Create category-19.php as above. Put in
    <div id="sticky-snip">I am not wearing any pants</div>
    above the Loop.

    Booyah.

    See http://codex.wordpress.org/Theme_Development for more details about WordPress Templates.

    In either of these cases, you just need to list the Category links with wp_list_cats. No Pages are needed. WordPress uses these new templates automatically.

    EDIT: As I said, I don't quite know what you are trying to do, so perhaps this does not address your issue at all.

  4. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    Q
    Which template does WordPress use for a Category with Category ID = 6?

    A
    The first template it finds from the following list:

    1. category-6.php
    2. category.php
    3. archive.php
    4. index.php
  5. Lorelle
    Member
    Posted 9 years ago #

    This is wonderful and might solve my problem. I write notes and descriptions about the specific categories to direct people since our site is so vast. Let me poke at it for a few days and I'll let you now how badly I've mangahhhlllled my test site.

    I already accidently put the permalink code in the htaccess of the root of my site and not the wordpress test directory and totally had my site screwed up for two weeks because I didn't "look"....ain't this fun.

  6. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    Let me know. I plan on putting this into Codex.

  7. zaea
    Member
    Posted 9 years ago #

    I have a related question: I'm trying to use WP1.5 as a basic CMS for a nonprofit advocacy organization. I'm using the static pages for content that won't be changing frequently, and am looking to use the posts for easily adding frequently updated content.

    As such, I'm using different post categories for each section or "function" of the website. So I have a category for press releases, one for this week's legislative committee schedule, one for our lobbyists' daily journal, and so on. Having a separate category template for each of these sections is absolutely essential, since I would like to include different sidebar information for each type of information.

    My questions:
    -->Is there a way to have specific post templates for each category?
    -->Can you have a specific template sub-categories, also?
    -->What would each be named?

    Thanks so much for your help!

  8. moshu
    Member
    Posted 9 years ago #

    See Cateory Templates on this page in the Codex:
    http://codex.wordpress.org/Templates

  9. zaea
    Member
    Posted 9 years ago #

    Thanks Moshu!

    I forgot about the custom page templating, but what I was looking for was a way to have specific post templates be used automatically...I guess I'm not convinced that the folks who will be doing the postings will select the correct template and such (it's hard enough to have them select the proper category).

    I wasn't sure if the the category-XX.php template system had been expanded for subcategories or if there was a way to "force" post templates for specific categories and subcategories. If it's too much work, I'll probably just invest the time in training and monitoring...I was just hoping to make it as idiot-proof as possible.

    Thanks.

  10. goodfish
    Member
    Posted 9 years ago #

    I am feeling foolish, but I have followed all mdawaffe's instructions for Case#2, but still don't get the sticky's showing up. I am stumped by what you mean when you say "In either of these cases, you just need to list the Category links with wp_list_cats" . Is there any chance someone could walk me through that? I am using a template.

  11. Lorelle
    Member
    Posted 9 years ago #

    The tag wp_list_cats has step by step instructions on the Codex on how to list your categories, including excludes and such.

    I have over 30 different category-x.php files on my site and it is working like a dream. I only created these "special" category templates for the categories that I wanted to put some html text on that basically said: <i>This category is about X, Y, and Z</i>.

    I have single custom sidebar for every one of these category pages that is different from the rest of the posts (similar but different) and customizing these to "look" different is really easy.

    I don't know what you mean by "sticky" as these are just category pages. A "sticky" is the effect of forcing a post to rise to the top of the Loop listing of posts and is, as far as I know, only done through the use of a plugin like Adhesive or something like that. Check http://www.wp-plugins.net for new sticky-plugins.

  12. qbert72
    Member
    Posted 9 years ago #

    Don't know if this is of any relevance, but here is a quick way to have your category description appear on top of category pages (mdawaffe's case 2) without multiplying your template files.

    Put the following outside the loop in your category.php template file:

    <?php if (!('' == category_description())) : ?>
    <div class="categorydescription"><?php echo category_description(); ?></div>
    <?php endif; ?>

    Style at will, and voilà! The category description is the one you enter in the admin area. It accepts basic HTML, as far as I can tell.

  13. dtclarinet
    Member
    Posted 9 years ago #

    I've read all the above. I'd like to have a category page with all the posts in that category listed in the side bar. Each category would have the same layout with different content and sidebar listings.

    Is there some way to use a single "category.php" and have the sidebar php ask for the posts to list? I was going to copy the page.php, add the code above to list the "category description", and have a new sidebar.php to query the posts list of the category. Can I add a generic php query to just list the posts in the sidebar? I don't need anything else there.

    thanks,
    David

  14. Macross
    Member
    Posted 9 years ago #

    okay so by using the category-5.php, i could have a specific category display a different template. Now how do I tell it to use a different template?

  15. Macross
    Member
    Posted 9 years ago #

    I forgot to add:

    Would this mean that any post under that topic would use that specific template?

    It would be nice if the codex had full instructions on what needs to be in category-X.php.

  16. moshu
    Member
    Posted 9 years ago #

    1. You don't have "to tell" anything: WP knows what to look for... see Template Hierarchy in Codex.

    2. Depending how do you build your template(s). See detailed instructions and examples in this thred

    3. http://codex.wordpress.org/Category_Templates

  17. sysmom
    Member
    Posted 9 years ago #

    I'm not new to content, php, or mysql, but I am to Word Press. I have looked at the Codex about using the 'category-#' file to control the appearance of a specific category number. Excellent planning!

    What I am not seeing is probably because I am just too new. But when it says to use the index.php as a template for the category-#.php file, *which* index.php file does it mean, and which dir does WP look for these category*.php files? The root? In a theme? Somewhere else?

    Thank you.

    deb

  18. haiiro
    Member
    Posted 8 years ago #

    qbert72, words can't express how grateful I am for your post!

    I've been trying to find a way to put unique headers on my category pages without creating 10+ separate pages (a nightmere to update), and your approach is perfect. Thank you!

  19. krbmedia
    Member
    Posted 7 years ago #

    Is there an easy way to have categories for the pages not just the posts?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.