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
- Change woo status automatically [closed]
- Apply WordPress function on specific woocommerce product categories only
- display a widget on specific category and its sub categories
- Multiple selection for wordpress widget
- Show all tags within a category?
- Filter WooCommerce archive pages by an additional category
- So my theme doesn’t have a category.php file
- Post not populating for custom post type based on category selection
- Force category choice before creating new post
- Post by category+author not working!
- Custom template for sub-sub-categories
- Show different title on category page
- Listing posts under a category by date
- Display content from a specific category using cat ID not working
- Display list categories from CTP
- Category url generate 404 error
- Dropdown menu for subcategories
- Exclude Category ID in function
- Different CSS class by category
- Trying to create a Categorised Index (archive?) to use as my Home Page
- Portfolio Filter Buttons Wont Work
- How to add categories on a page [duplicate]
- Allow user to select categories that will display in post loop
- Problem with calling custom function in a foreach loop
- Show parent categories and sub categories but not grand children categories
- How to remove one specific category (uncategorized) from post permalinks
- Filter posts by categories ajax is showing nothing
- Combining a meta_query with a category filter
- How to display child categories of all parent category within a singe loop?
- Grandchild Term Things Grandfather Term is It’s Parent
- how to nest specific category thumbnails inside different containers
- Insert HTML content in WP Query at specific point
- get full category structure by post id
- Eliminate word from $term->name
- What Must to Display the “mysite.com/category” URL?
- Display Related Posts by “Category” “by Author”
- Root category template?
- Searching for a category returns nothing if category is empty
- Wrong category nice name is displayed on archive page
- “Virtual category page” based on a custom field filter
- Specify multiple categories for custom post template – FATAL ERROR
- Query (built in) Categories and Advanced Custom Fields?
- Custom Permalink with child categories creating 404
- Get next post in same category not working WP 4.7.4
- Category page not showing
- How do you use the featured image of the most recent post in a category as the background image
- Posts from a category on homepage with category archieves page default css
- WordPress Customizer: Dropdown with Category output
- Custom tax_query filter not working for Woocommerce product categories
- How do I retrieve the category ID (ugly permalinks) in my sub-navigation menu?
- display a link to all the categories of current post, including parents
- display specific category on page
- function query_posts disabling current_page_menu class
- Group search results by category
- Notice: Undefined variable: category_id
- Custom page category taxonomy 404
- How do order product categories – on a parent category page – in Woocommerce?
- Simple way to style posts of a single category differently in the loop and in single
- Template hierarchy: how to let category.php conditionally-load archive.php?
- show WordPress categories with different Structure
- “All posts” in the category widget
- WP 4.7 in_category change?
- display category list year wise in wordpress
- set terms to category and subcategory
- Woocommerce filter function not updating