WordPress.org

Ready to get started?Download WordPress

Forums

PHP and CSS Help! ... I'm lost with IF {echo} (4 posts)

  1. tom711
    Member
    Posted 3 years ago #

    Basically I want to display a list of categories at the bottom of my post like :

    Categories: category1, category2, category3

    ----------------------------------------
    I had a hard time getting <span> to work with the "IF" statement, so I used an "echo" around it.

    if (is_single()) { echo '<span class="cats">'.the_category(' • ').'</span>';

    Problem is it displays like this instead:

    category1, category2, category3 Categories:

    -----------------------------------------
    This is what I have in my CSS:

    .cats {
    	background: transparent url(images/categories.gif) 0 1px no-repeat;
    	margin: 0;
    	padding-left: 25px;
    	padding-bottom:5px;
    	font-family: Tahoma, Geneva, Verdana, sans-serif;
    	color: #888;
    	font-size: 12px;
    	content: "Categories: ";
    }
    
    .cats:before {
    	content: "Categories: ";
    }

    I'm not that good with PHP or CSS (still learning), and would appreciate any help I can get right now.

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    a:
    you could output 'Categories' from within the php code:

    if (is_single()) { echo '<span class="cats"><strong>Categories: </strong>'.the_category(' • ').'</span>'; }

    and get rid of the css content: "Categories: ";

    b:
    to comment on the css output, i would need to see the problem live in your site.

  3. SpankMarvin
    Member
    Posted 3 years ago #

    Since you are echoing, does using get_the_category work?

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    @SpankMarvin: well spotted, that is it ;-)

    if (is_single()) { echo '<span class="cats"><strong>Categories: </strong>'; the_category(' • '); echo '</span>'; }

Topic Closed

This topic has been closed to new replies.

About this Topic