• I have two types of posts on my blog.

    1. Normal written posts, sometimes I upload a post-preview image, sometimes not

    2. Automatically generated “video-posts”, that are created by the “automativ youtube video posts” plugin. The plugin makes it also possible to use the preview image from youtube.

    And here’s what I wanna do:

    If there is a youtube preview picture wordpress should use it as post-preview picture, if there is a uploaded preview picture – wordpress should this one instead of the youtube one – and if there is no picture at all – wordpress should dissplay nothing (at the time its using the default image from youtube (grey camera icon).

    Heres my code, the bold parts are the one I added (don’t get confused by the <span> tag thats just to cut of the letterbox from the youtube images):

    <div class="post">
                    <?php if ( has_post_thumbnail() ) echo '<a href="'.get_permalink().'">'.get_the_post_thumbnail($post->ID, 'slide',
                        array(
                            'alt'	=> trim(strip_tags( $post->post_title )),
                            'title'	=> trim(strip_tags( $post->post_title )),
                        )).'</a>'; ?>
    
                   <span class="crop-slider"><a href="<?php the_permalink(); ?>"><?php tern_wp_youtube_image(); ?></a>
                   </span>
    
                    <div class="post-category"><?php the_category(' / '); ?></div>
                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    
                    <div class="post-meta">von <span class="post-author"><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" title="Posts by <?php the_author(); ?>"><?php the_author(); ?></a></span> am <span
                            class="post-date"><?php the_time(__('j. M. Y')) ?></span> &bull; <?php comments_popup_link(__('Keine Kommentare'), __('1 Kommentar'), __('% Kommentare'), '', __('Kommentare gesperrt') ); ?> <?php edit_post_link( __( 'Eintrag bearbeiten'), '&bull; '); ?></div>
                    <div class="post-content"><?php if ( has_post_thumbnail() && function_exists('smart_excerpt') ) smart_excerpt(get_the_excerpt(), 50); else smart_excerpt(get_the_excerpt(), 150); ?></div>
                </div>
  • The topic ‘[PHP Coding] Use Article thumnail or else use image from other source’ is closed to new replies.