Forums

[resolved] Different styles for different Archives? (7 posts)

  1. JGrizzLee
    Member
    Posted 10 months ago #

    I'm trying to have two different styles that are called depending on which category is being displayed in archive format. So most pages would display in the exact same format, but a couple categories like News and Reviews would display in a different format. I already know the styling, I'm just wondering what the proper if/then code would be, or if there's a better way to do this.

  2. alchymyth
    The Sweeper
    Posted 10 months ago #

  3. JGrizzLee
    Member
    Posted 10 months ago #

    Hmm, maybe I missed something, but I didn't see anywhere in that article as to how exactly to make different templates to display category archives with different styles. The article seemed to show more basic stuff like how to add text before the posts are displayed, but I'm talking about having two different archive styles that display posts differently.

    Would adding a new template file and then adding the code:

    <?php
     {
       query_posts("cat=4");
     }
    ?>

    be the best way to do this, or is there a better way?

  4. alchymyth
    The Sweeper
    Posted 10 months ago #

    a category template will show only posts of that category (and childs of it);
    you can then change the html structure, output, etc, and style it as you like.

    if yo mean simple style changes with css, then look into the output of body_class() which will output a category specific css class for each category archive:
    http://codex.wordpress.org/Function_Reference/body_class

  5. JGrizzLee
    Member
    Posted 10 months ago #

    Thanks for the replies alchymyth, but I actually understand how to change the style of a archive page via the body classes. My question is how exactly to make a new template file be called by different categories and if the code I posted above if the proper way to only display posts from a single category.

  6. alchymyth
    The Sweeper
    Posted 10 months ago #

    I actually understand how to change the style of a archive page via the body classes.

    that is what i thought as well, therefore i pointed to category templates.

    how exactly to make a new template file be called by different categories and if the code I posted above if the proper way to only display posts from a single category.

    that would be a category template, as in the link i posted.

    category templtes by default display the posts of a single category and of the child categories of it;
    to really change that into a single category, you would need to add a bit of code before the loop;

    something like:

    <?php
    global $wp_query;
    $args = array_merge( $wp_query->query, array( 'category__in' => array( get_query_var('cat') ) ) );
    query_posts( $args );
    ?>

    http://codex.wordpress.org/Function_Reference/query_posts#Usage_Note

  7. JGrizzLee
    Member
    Posted 10 months ago #

    Thanks

Reply

You must log in to post.

About this Topic