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="https://wordpress.stackexchange.com/questions/58811/<?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.
Related Posts:
- Get rid of WordPress category, tag and author archives?
- How to add the category ID to admin page
- How to create a widgetized sidebar for every category dynamically?
- Only show category to certain user levels without plugin
- List Categories of the Parent Category of the Current Category
- exclude category from WordPress Form function
- wp_list_categories, Add class to all list items with children
- Remove “Parent” Selection When Adding/Editing Categories?
- Check is category parent or not from its ID
- How to show in search results posts with a particular tag in a particular category?
- How can I get an tag to wrap each ancestor that gets outputted in this condition?
- If category is in parent category?
- Rename Default Category (Uncategorized) Via a Function
- Check child/parent categories if exists
- Getting URL of archive (category) page
- How to show only one category in breadcrumb navigation
- Query posts from category based on a filter most favorited
- Add tag parameter to category.php
- Random Featured Image Based on Category
- add slug beside name in Admin Category Checklists
- Change div background acording to the selected category
- How to use wp_list_categories with plugin category?
- Redirect depending on category chosen
- How to add icon over specific thumb
- How to load several hierarchical categories from functions.php
- Change Default Content when Creating a Post based on Previous Category Choice
- How to add a custom thumbnail size for a specific category?
- create function to call category name and slug
- Different size video display for category page (smaller) & detail page (larger)
- Code to display category-specific single.php is overriding normal single.php, too
- Loop Through Categories in Custom Field
- Function to list posts from current post’s category fails in WP 3.8
- How to get tags and categories?
- Show only one category in main query, issues on tag page
- Show parent-child relationship for categories in the wordpress admin
- How to create an automatic MultiColoumn MegaMenu with Categories WordPress
- Different template for subcategories
- Category Archive, list subcategories of each post
- Disable pagination only for specific category
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- How to add categories to products in woocommerce programatically? [closed]
- Is there a plugin that will completely remove the category system?
- How to get only the last child of category slug?
- Remove Parent Category from Child Category URL
- Multisite – create a category in specific site
- How do you remove display of WooCommerce product category on single product page?
- How to disable category without deleting?
- Limit number of terms that a custom taxonomy can save per custom post type
- Populate dropdown based on selection of parent category
- query cat orderby and order not working
- WooCommerce – How to show specific category first-rest of products-specific category last
- Multiple URL’s based on category for one post
- WordPress category check
- Exclude categories from wp_list_categories by category slug
- Can’t delete a category in WordPress
- WordPress Categories in data-groups
- Get Categories Where Taxonomy Equals ‘n’
- How to access deleted term inside delete_product_cat action
- Remove Archive | from Categories
- Showing Categories for Page Edit – without plugin
- Difference between wp_list_categories and get_categories
- Show different menu on each woocommerce category page
- Have posts that belong to multiple categories, exclude some categories from homepage
- Only first category!
- How could I write a get_categories_by_year() function?
- add_settings_field (exclude categories->reading) wp_category_checklist
- Retrieve post tags from from main wp_query
- Listing Post Categories on Home Page
- Get posts in a subcategory of a chosen parent
- Exclude category from drop down list form
- How to set the same base url for two different taxonomies?
- Hide category name but show posts
- Parent Category and Subcategory default text generated with category
- Post List by category and under custom taxonomy
- How to create a table with counts of category combinations?
- product_cat image url from database
- Multiple if statements with else for get_the_category [closed]
- Balance Tags to the_content Words Length
- How to create template for children category?
- Using a template page parent breaks page
- Setting category for post as default
- Query post only from categories that have subcategories
- How to get the link of all categories
- foreach,having wp_query inside, breaks after showing one result
- Display a category name automatically using code in the functions.php file
- Removing categories, Comments etc from posts?
- Trying to see if page is category or single and displaying title with appropriate heading tag
- Include Category Description in search result
- All post of child category not in top category
- How to add a tag above a category post that displays the category name in WordPress
- Woocommerce – Display product category of product in Orders page
- How to show video from wp option value?
- Changing Woocommerce categories programatically
- Add an Exclusive or featured tag line to article titles
- How to list out post category name and description in page
- How to link ACF relationship field to the new Query block in Full Site Editing
- Order Categories by Character Count
- how to create a page that shows all of multiple category posts on a single page
- Quick Edit on taxonomy names results in error
- how to create twitter card without plugin in wordpress website?