2017-04-13 36 views
1

我正在更新我的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

回答

0

只需添加在這裏

<!-- 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)」錯誤:/另外,我想我可以通過使用這個'<?php the_post_thumbnail(array(120,120),array('class' =>'u-featured'));'如果那看起來好嗎? – user1406440

相關問題