Icon over thumbnail according to post format

admin2025-06-03  3

How would I go about adding icons over post thumbnails according to their post format. So for example if I have a post with a post format of audio the thumbnail would show everywhere(widgets, category pages, home page, etc) with an audio icon over it. Can't seem to be able to figure out how to implement this.

How would I go about adding icons over post thumbnails according to their post format. So for example if I have a post with a post format of audio the thumbnail would show everywhere(widgets, category pages, home page, etc) with an audio icon over it. Can't seem to be able to figure out how to implement this.

Share Improve this question asked Dec 31, 2015 at 9:45 MadeirenseMadeirense 1532 silver badges19 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

You can use get_post_format($post_id) to retrieve each post's format, then you can assign a class to each post based on it's format.

Once you have that, you only need to define said classes to, for example, show an icon overlay on the ::after pseudo-element of the posts.

To obtain consistency between widgets, category pages, etc. you can either apply the previous to each or use a unified post template for everything.

Code elaboration for answer provided by @Leuquim

$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";

//Check for current post type using get_post_type( $post )

//Check the current post type and assign classes accordingly

if($input[$rand_keys[1]] == "Neo")
{
  $class_assigned = "audio_post"
}
else if($input[$rand_keys[1]] == "Cypher")
{
  $class_assigned = "video_post"
}

//so on and so forth

And accordingly you can add the CSS rules for adding a post type specific icon.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748955482a315132.html

最新回复(0)