Last active
January 2, 2016 23:29
-
-
Save ingozoell/8376472 to your computer and use it in GitHub Desktop.
Standard-Thumbnails für Kategorien
From http://fastwp.de/snippets/standard-thumbnail-fuer-jede-kategorie/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function default_category_featured_image() | |
{ | |
global $post; | |
$featured_image_exists = has_post_thumbnail($post->ID); | |
if (!$featured_image_exists) | |
{ | |
$attached_image = get_children("post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1"); | |
if ($attached_image) | |
{ | |
foreach($attached_image as $attachment_id => $attachment) | |
{ | |
set_post_thumbnail($post->ID, $attachment); | |
} | |
} | |
else if (in_category('ID DER KATEGORIE 1')) | |
{ | |
set_post_thumbnail($post->ID, 'BILD ID'); | |
} | |
else if (in_category('ID DER KATEGORIE 2')) | |
{ | |
set_post_thumbnail($post->ID, 'BILD ID'); | |
} | |
else if (in_category('ID DER KATEGORIE 3')) | |
{ | |
set_post_thumbnail($post->ID, 'BILD ID'); | |
} | |
else if (in_category('ID DER KATEGORIE 4')) | |
{ | |
set_post_thumbnail($post->ID, 'BILD ID'); | |
} | |
else | |
{ | |
set_post_thumbnail($post->ID, 'BILD ID FÜR ALLE ANDEREN FÄLLE'); | |
} | |
} | |
} | |
add_action('the_post', 'default_category_featured_image'); | |
add_action('save_post', 'default_category_featured_image'); | |
add_action('draft_to_publish', 'default_category_featured_image'); | |
add_action('new_to_publish', 'default_category_featured_image'); | |
add_action('pending_to_publish', 'default_category_featured_image'); | |
add_action('future_to_publish', 'default_category_featured_image'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment