WordPress.org

Ready to get started?Download WordPress

Forums

category images using category description (4 posts)

  1. vachi
    Member
    Posted 5 years ago #

    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

  2. Chris_K
    Member
    Posted 5 years ago #

    Does this plugin do what you're after?
    http://wordpress.org/extend/plugins/category-icons/

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

  3. vachi
    Member
    Posted 5 years ago #

    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
    http://blah.com/blog/post-name/%3Cp%3Ehttp://blah.com/blog/files/2009/03/image.png%3C/p%3E

    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
    http://vitamovie.com/anime/eureka-seven-episode-50/

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

  4. mores
    Member
    Posted 4 years ago #

    Why don't you try using the category id?

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

    <?php
    	if (is_category()) {
    		$cur_cat_id = get_cat_id( single_cat_title("",false) );
    	}
    	if (is_single()) {
    		$category = get_the_category();
    		$cur_cat_id=$category[0]->cat_ID;
    	}
    	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="http://www.carlosdemello.com/wp-content/uploads/background_'.$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)

Topic Closed

This topic has been closed to new replies.

About this Topic