WordPress.org

Ready to get started?Download WordPress

Forums

Changing class on different category (7 posts)

  1. ZBRob
    Member
    Posted 9 years ago #

    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 :(

  2. Mark (podz)
    Support Maven
    Posted 9 years ago #

    Try the per-post styles ?
    http://www.blindmuse.com/wordpress/

  3. random
    Member
    Posted 9 years ago #

    Do you mean like PhotoMatt's "asides"?

  4. ZBRob
    Member
    Posted 9 years ago #

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

  5. eric
    Member
    Posted 9 years ago #

    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(); ?>
    <?php
    /* 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">
    <?php
    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
    echo("</h2>");
    _e("Filed under:");
    the_category();
    edit_post_link(" - [edit]");
    echo ("</div>");
    }
    echo sprintf("\n<h1");
    if (!$dynamic_cat)
    echo sprintf (' class="static"');
    echo sprintf (">
    the_permalink();
    echo ("'>");
    the_title();
    echo ("
    ");
    if (!$dynamic_cat)
    edit_post_link(" - [edit]");
    echo ("</h1>");
    /* end of horrible hack */
    ?>
    <div class="storycontent">
    <?php the_content(); ?>
    </div>
    </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

  6. eric
    Member
    Posted 9 years ago #

    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:

  7. ZBRob
    Member
    Posted 9 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.