Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Center area post/pages (http://forum.bytesforall.com/forumdisplay.php?f=32)
-   -   Style each post differently by category (http://forum.bytesforall.com/showthread.php?t=11920)

lisyan Dec 29, 2010 10:41 AM

Style each post differently by category
 
Hi!

I'm trying to reach my 'ideal template' using atahualpa. The most important need I have is to mark all the post of certain category with a distinctive background color.

I found this article which suggest to use the post_class PHP function.

I tried to add this in ATO--->Style/edit Center Column---> The Loop
before </div><!-- / Post -->

PHP Code:

<div id="post-39" class="post post-39 category-8 category-test logged-in"

and then in CSS/HTML Insert
Code:

.category-test {background: #00ff00; border: 1px solid #84aac4;}

but with no result...do you have some suggestions?
thanks thanks =)

juggledad Dec 29, 2010 01:47 PM

since all the posts have a category class like 'category-uncategorized', why not use that

HTML Code:

div.category-uncategorized {background-color: blue;}
div.category-announcements {background-color: yellow;}


lisyan Dec 29, 2010 03:43 PM

thanks for your reply juggledad!

Surely I'm doing something wrong ...
I tried adding " div.category-announcements {background-color: yellow;} " in CSS Inserts but
nothing happened =(
Did you mean that using div.category-name php code is not necessary?

juggledad Dec 29, 2010 04:42 PM

You need to use the names of your categories
No you don't need to add anythingng.

View your page, theview the source and you should be able to find your category names.

lisyan Dec 30, 2010 05:08 AM

ouch! It works!
but only in the category page view.
What I need is to have different post background only in the front-page.. uhm,

juggledad Dec 30, 2010 05:53 AM

What is the URL?

lisyan Jan 10, 2011 06:04 PM

Quote:

Originally Posted by juggledad (Post 53212)
What is the URL?

here the homepage, and it doesn't work :(( http://yupyup.altervista.org
and here there's the category page, where the "div.category-name" works perfectly: http://yupyup.altervista.org/?cat=8

hmmm strange... maybe I've to do this via php? with 'if is front page'?

thanks and sorry for the late reply =))

juggledad Jan 10, 2011 06:20 PM

You have code that is changing the front page from a single column to multiple columns. That code is not putting the category type of the <div> for the posts. You need to fix that for it to work.

lisyan Jan 11, 2011 05:50 PM

Quote:

Originally Posted by juggledad (Post 54320)
You have code that is changing the front age from a single column to multiple columns. That code is not putting the category type of the <div> for the posts. You need to fix that for it to work.

ok, I've now added this in the LOOP

<div class="post_footer">
<p class="postmetadata"> <?php the_category(', ') ?>
</div>

but the problem persists.. hmmm

juggledad Jan 11, 2011 06:32 PM

Did you look at a generated page to see how atahualpa named the category classes?

lisyan Jan 11, 2011 06:45 PM

I think I get lost... :(

juggledad Jan 11, 2011 07:27 PM

The class name needs to be 'category-yourcategoryname' so the CSS can be applied. You are not creating that type of class name in your code.

lisyan Jan 12, 2011 05:17 AM

I tried adding this in the Loop: <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

But the result is this: http://yupyup.altervista.org/ and no css effect.

juggledad Jan 12, 2011 05:32 AM

you are creating a mess for yourself. here is one of your posts
HTML Code:

<div id="new_central_pos_30">
        <div class="post_footer">
                <p class="postmetadata">
                        <a href="http://yupyup.altervista.org/?cat=1" title="View all posts in Uncategorized" rel="category">Uncategorized</a>
        </div>
        <div class="post-headline">               
                <h2><a href="http://yupyup.altervista.org/?p=50" rel="bookmark" title="Permanent Link to ARAYA">ARAYA</a></h2>       
        </div>
        <div class="post-byline">
                Jan 10th, 2011, <img src="http://yupyup.altervista.org/wp-content/themes/atahualpa353/images/icons/comment-gray.gif" alt="" />
                <a href="http://yupyup.altervista.org/?p=50#respond" class="comments-link"  title="Comment on ARAYA">Commenta</a>
        </div>
        <p>De Quincey was oppressed by debt for most of his adult life; along with his opium addiction, debt was one of the primary constraints of his existence.[15] He pursued journalism as the one way available to him to pay his bills; and without financial need it is an open question how much writing <span style="color:#777"> &rarr; <a href="http://yupyup.altervista.org/?p=50">Read+ </a></span>[...]

        <div id="post-50" class="post-50 post type-post hentry category-uncategorized">

<!-- / Post -->

        </div>

you are missing the closing </p>
you are missing a closing</div>
you have the content of the post before the <div> for the post
and who knows what else

Custom changes like this to the theme are really beyond the scope of the forum. If you are unsure about how to do detail customization and how php/css work, you might want to put a post in the Customization, Design, Programming... section and see if you can hire some one to help you out.

lisyan Jan 12, 2011 12:23 PM

I feel sorry.
But I just used the code found here: http://forum.bytesforall.com/showthread.php?t=4220
with a small change to have only the three column part.

What you saw (that huge mess :) ) happened when I added
" div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> ". Now,moved away that code, the homepage looks normal.

Anyway, considering the errors you reported, maybe there are problem with that code?


thanks and sorry for my ignorance =)

Tamara-IT Jan 21, 2011 07:03 PM

Hello,
I had the same question and tried to add
Code:

div.category-NAME {background-color: yellow;}
in my CSS inserts. It did not work.
I then inserted a SPACE between "div" and the dot...
Code:

div .category-NAME {background-color: yellow;}
and I had my colored background.:)


All times are GMT -6. The time now is 07:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.