• Resolved York

    (@york)


    I would like to include category-specific images with the titles of my posts.

    Click here to see what my goal is.

    I followed these directions and put the following code

    <?php foreach((get_the_category()) as $cat)
     { echo '<img src="https://www.yorkrules.com/yorkrules3/global/images/categoryIcon/' . $cat->cat_ID . '.jpg"
    alt="' . $cat->cat_name . '" />'; } ?>

    into the index.php as follows

    <div class="contenttitle">
    <?php foreach((get_the_category()) as $cat)
     { echo '<img src="https://www.yorkrules.com/yorkrules3/global/images/categoryIcon/' . $cat->cat_ID . '.jpg"
    alt="' . $cat->cat_name . '" />'; } ?>
    	<h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    	<?php the_time('F j, Y'); ?> | <?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?>
    
    	</div>
    	<?php the_content(__('Read more'));?>
    	<!--
    	<?php trackback_rdf(); ?>
    	-->
    
    	<?php endwhile; else: ?>

    I also saved the category-specific images in the ‘categoryIcon’ folder, named after their related category IDs (e.g. ‘4.jpg’ for the ‘look’ category, which is ID 4).

    Unfortunately, I saw no effect on my posts.

    Not being familiar with PHP, perhaps I haven’t correctly modified the PHP code? Any ideas or advice would be greatly appreciated.

    Thanks,

    York

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter York

    (@york)

    I continue to troubleshoot this, but without success. Any assistance you can offer would be great. Thanks!

    Thread Starter York

    (@york)

    Bueller?

    Thread Starter York

    (@york)

    My error. I needed to insert the code

    <?php foreach((get_the_category()) as $cat)
     { echo '<img src="https://www.yorkrules.com/yorkrules3/global/images/categoryIcon/' . $cat->cat_ID . '.jpg"
    alt="' . $cat->cat_name . '" />'; } ?>

    in four different pages in my theme (archive, home, index, search).

    It works now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Category Image in Post’ is closed to new replies.