Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this code in WordPress index.php and I was wondering how can I transfer this in to a functions.php to be a part of a function?

<?php if (in_category('featured')) : ?>
<a href="<?php the_permalink(); ?>">  <span  class="featured_icon">     
<img src="<?php bloginfo('template_directory'); ?>/images/featured_icon.png" />  
</span></a>                     
<?php endif; ?>

Thank You in advance for Your help :)

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

If you want to use the function to output the code somewhere:

function displayImage($currentPost) {

    // Show the featured icon only if current post is in "featured" category
    if ( in_category ( 'featured', $currentPost ) ) {

        $output = '<a href="<?php the_permalink(); ?>">
                            <span  class="featured_icon">
                                <img src="<?php bloginfo('template_directory'); ?>/images/featured_icon.png" />  
                            </span>
                      </a>';
    }

    else { $output = '' };
    return $output;

}

Then you can just pass the post id and echo the function.

share|improve this answer
1  
Edited to make the code more readable. Hope you dont mind. :) –  its_me Jul 18 '12 at 3:10
    
@AahanKrish Thank You :) Any idea how to place it inside this code to be a part of a function from pastie here: pastie.org/4276093 in between line 16 and 19? I really need help :) –  jimilesku Jul 18 '12 at 5:33
    
@fdsa Thank You :) Any idea how to place it inside this code to be a part of a function from pastie here: pastie.org/4276093 in between line 16 and 19? I really need help :) –  jimilesku Jul 18 '12 at 6:22
    
@AahanKrish Thank you! –  fdsa Jul 19 '12 at 0:03
1  
@jimilesku just place this function inside your functions.php and then somewhere you should have a $display.= displayImage($post->ID) –  fdsa Jul 19 '12 at 0:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.