Support » Plugins » category images using category description

  • i have been trying to display category image by putting a image link in the category description area than calling the category description inside a img tag as the image src

    now this does not work here is my code

    <?php foreach(get_the_category() as $category)
    			{ $thecat = $category->cat_ID; } ?>
    			<?php $catImage = category_description($thecat); ?>
    			<?php echo $catImage ?>
    			<img src="<?php echo $catImage ?>" />

    now <?php echo $catImage ?> this displays the category description text

    but the image does not show because wordpress is putting some weird things in the call

    any solutions or suggestions are greatly welcome
    i am thankful in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Does this plugin do what you’re after?

    If so, you could either use it or examine code to get a feel for how he does it?

    tx for the reply, yeah i looked at that plugin before, i am more after displaying the category image in single.php

    the problem with the current code i have is that the img source comes out to be this

    so it adds these p%3E to the beginning and end of the text and on top of that ads the post link at the beginning

    example where i am using it

    i really want to find a non plugin solution where i can just use the given wordpress category description field

    Why don’t you try using the category id?

    I created a site where I used background images on a per-category basis.

    	if (is_category()) {
    		$cur_cat_id = get_cat_id( single_cat_title("",false) );
    	if (is_single()) {
    		$category = get_the_category();
    	if (is_page()) {
    		$cur_cat_id = $post->ID;
    	if ( ($cur_cat_id) && (file_exists('/home/.sites/1234/site567/web/wp-content/uploads/background_'.$cur_cat_id.'.jpg')) ) {
    		echo '<img class="background_image" src="'.$cur_cat_id.'.jpg">';

    I put this in the header.php file, it inserts an image that is then used as full-screen background using css magic 🙂
    To get the category images up into the uploads directory, simply add them to the media library directly (not with the media upload button when editing/writing posts)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘category images using category description’ is closed to new replies.