WordPress.org

Support

Support » Themes and Templates » PHP and CSS Help! … I'm lost with IF {echo}

PHP and CSS Help! … I'm lost with IF {echo}

  • 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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.

    Since you are echoing, does using get_the_category work?

    @spankmarvin: well spotted, that is it 😉

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP and CSS Help! … I'm lost with IF {echo}’ is closed to new replies.
Skip to toolbar