Support » Plugins » Changing class on different category

  • Is there a way to change the lay-out of a post if it’s in the category Links, or 5 or whatever? Or do I have to enter php mode in Trial-and-Error, which it was last time I tried 🙁

Viewing 6 replies - 1 through 6 (of 6 total)
  • Mark (podz)


    Support Maven

    Try the per-post styles ?

    Do you mean like PhotoMatt’s “asides”?

    Well? Is there a method for doing this in 1.0.2, at least untill I upgrade to 1.2?

    Perhaps zou can adapt this code for what zou want to do. I use it here to give categories with static content a different heading style (with no date) than the categories where stuff gets posted regularly. Should be easy to change so it changes the whole post rather than just the heading. I use it with WP1.2 but see no reason it wouldn’t work with 1.0.2. BAsically I just replace the whole “content” div with this: (warning, ugly coding style ahead)
    <div id="content">
    <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    /* horrible hack to make the date display in dynamic categories only, these need to be specified explicitly below */
    $dynamic_cat=(in_category(1) or in_category(2) or in_category(3) or in_category(4) or in_category(5) or in_category(6) or in_category(14) or in_category(15));
    <div class="post">
    if ($dynamic_cat)
    echo sprintf("<div class='meta'><h2>");
    the_time('j.n.Y'); // when 2 posts have same date, the_time shows it twice, the_date just once
    _e("Filed under:");
    edit_post_link(" - [edit]");
    echo ("</div>");
    echo sprintf("\n<h1");
    if (!$dynamic_cat)
    echo sprintf (' class="static"');
    echo sprintf (">
    echo ("'>");
    echo ("");
    if (!$dynamic_cat)
    edit_post_link(" - [edit]");
    echo ("</h1>");
    /* end of horrible hack */
    <div class="storycontent">
    <?php the_content(); ?>
    </div> <!--end of "post" div -->
    /* deleted the php code to display comments; I don't use them */
    <?php endforeach; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>
    </div><!-- end of content div -->

    then I add something to my style sheet to display the h2 class=”static” stuff differently

    Where it says \ that should be backslash n for newline. What you probably want to do is apply the conditional statement around the whole “post” div so you end up with either div class=”post” or div class=”post-specialstyle”, depending on the category. HTH:

    Yup. Thanks. I’ll go work with it, and I’ll let you know.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Changing class on different category’ is closed to new replies.