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
- Retrieve Product category ‘NAME’ by product category ID – WooCommerce?
- Could not insert term into the database
- Activate Gutenberg in category-descriptions
- How to show subcategories in categories else show posts
- Weird behaviour when adding terms/term_taxonomies programmatically
- How can I get category ID by category name?
- How would I increase the Author Role to be able to add a new category?
- How to remove the parentheses from the category widget
- Filter front page posts by category
- Randomise results from a category page?
- How to get the url to tag & category base set by the user?
- Adding Custom User Profile data based upon Categories
- How to: 301 Redirect /category/ to /customname/
- List only child categories a post is in, of a specific parent category
- Custom Query to search through categories
- write in functions.php
- Root level category, tag, author and archive pages to work
- Order posts by category name
- How can I make wp_list_categories output li with category-slug as class, for its children?
- How to set child post categories to parent post categories when updating parent post?
- Get sticky post from category?
- Display one latest post from multiple categories
- Archive pagination causing 404 with permalinks structure
- Pinterest Integration Using functions.php
- Remove word “Category” from WooCommerce product page [closed]
- Get a list of Terms for a specific category
- Get a variable from object in array [closed]
- Remove Archive Headline and Archive Intro Text fields on category and tag archive pages in WordPress Admin with Genesis framework
- Date/time limitation of posts where function must be executed
- Output link to category from WP_Query loop of woocommerce products
- How Do I Merge Categories With phpMyAdmin
- Display name of the last child category
- Edit the markup of categories list
- Show category children, one level
- a-z list, categories and sub categories in loop
- Category slug $_SERVER[‘REQUEST_URI’];
- Using a portfolio_category slug in wordpress URL
- How do I specify more than one category?
- How to provide value for ‘selected’ on wp_dropdown_categories() for ‘multiple’ options
- Set the default category of an attachment
- exclude post from displaying in loop if it is in a category, but not in many categories
- Show Featured products in product category pages
- Need Category RSS Feed that shows all posts
- Custom HTML in specific category single page and its descendant categories
- Set post categories to include parents when setting child category
- Nav menu category links not showing
- Making a tourism information website [closed]
- How to remove category titles?
- Adding Categories Through Function
- Get only one of the current categories
- Show Available Taxonomy List with Current Category
- Exclude a category from the_category in the single post page
- WordPress search only showing a few posts
- Post publish directly in all categories except one need pending review
- Display category posts before others category custom query [closed]
- Get Prevous/Next Post Specific Category Without Excludes
- Pagination is not working properly in Product Category/Tag pages
- How to recreate a copy of a product category in WooCommerce? [closed]
- add_rewrite_endpoint returns 404 on archives
- Multiple category archive page
- List subcategories of active parent category (WooCommerce)
- How to display post type and category links in foreach WordPress code
- Updating category template to change how subcategories display
- Create menu / submenu from category subcategory and posts
- Add multiple classes. Different style for each category tag