$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Icon over thumbnail according to post format|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Icon over thumbnail according to post format

matteradmin7PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far