将默认占位符上的类添加到缩略图(Wordpress循环)

问题描述:

我正在更新我的loop.php中的类,并设法将它全部从图像类别中除去。除此之外,如果没有图像更新,我想包含一个默认的占位符图像。有人可以帮忙吗?将默认占位符上的类添加到缩略图(Wordpress循环)

这是我目前loop.php代码:

<!-- article --> 
<article id="post-<?php the_ID(); ?>" <?php post_class('h-entry'); ?>> 

    <!-- post thumbnail --> 
    <?php if (has_post_thumbnail()) : // Check if thumbnail exists ?> 
     <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="h-entry__image-link"> 
      <?php the_post_thumbnail(array(120,120)); 
     </a> 
    <?php endif; ?> 
    <!-- /post thumbnail --> 

    <!-- post title --> 
    <h2 class="p-name"> 
     <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> 
    </h2> 
    <!-- /post title --> 

    <!-- post details --> 
    <time datetime="<?php the_time('Y-m-j'); ?>" class="dt-published"><?php the_time('jS F Y'); ?></time> 
    <!-- /post details --> 

    <?php html5wp_summary('html5wp_index'); // Build your custom callback length in functions.php ?> 

    <p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="arrow-link">Read the full article</a></p> 

    <?php edit_post_link(); ?> 

</article> 
<!-- /article --> 

我确实需要使用修改我的functions.php我的摘要文本类以下内容:

function html5wp_summary($length_callback = '', $more_callback = '') 
{ 
    global $post; 
    if (function_exists($length_callback)) { 
     add_filter('excerpt_length', $length_callback); 
    } 
    if (function_exists($more_callback)) { 
     add_filter('excerpt_more', $more_callback); 
    } 
    $output = get_the_excerpt(); 
    $output = apply_filters('wptexturize', $output); 
    $output = apply_filters('convert_chars', $output); 
    $output = '<p class="p-summary">' . $output . '</p>'; 
    echo $output; 
} 

不知道如果我需要为图像做类似的事情,但我无法得到它的工作。

预先感谢,我希望有人能帮助:)

+0

的其他条件你的意思是像'the_post_thumbnail'? –

+0

你已经有'class =“h-entry__image-link”',你想改变它吗?或添加到它? – RST

+0

它是实际上'img'标签上的类而不是链接。然而,我想我可以通过在末尾添加另一个数组来实现这一点:'the_post_thumbnail(array(120,120),array('class'=>'u-featured'));' - 那看起来好吗?它似乎工作! – user1406440

只需添加在这里

<!-- post thumbnail --> 
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="h-entry__image-link"> 
    <?php if (has_post_thumbnail()) { // Check if thumbnail exists ?> 
      <?php the_post_thumbnail(array(120,120)); ?> 
    <?php } ?> 
<?php else {?> 
       <img src="path to default image" alt="<?php the_title(); ?>"/> 
<?php } ?> 
</a> 
    <!-- /post thumbnail --> 
+0

如果这将是被接受的答案,那么您至少可以重写代码以删除重复的命令。 – RST

+0

我更新了代码。核实。我希望这会对你有用。 –

+0

嘿,感谢您的代码!我得到一个“PHP解析错误:语法错误,意外'其他'(T_ELSE)”错误:/另外,我想我可以通过使用这个''u-featured'));'如果那看起来好吗? – user1406440