我正在更新我的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;
}
不知道如果我需要爲圖像做類似的事情,但我無法得到它的工作。
預先感謝,我希望有人能幫助:)
的其他條件你的意思是像'the_post_thumbnail'? –
你已經有'class =「h-entry__image-link」',你想改變它嗎?或添加到它? – RST
它是實際上'img'標籤上的類而不是鏈接。然而,我想我可以通過在末尾添加另一個數組來實現這一點:'the_post_thumbnail(array(120,120),array('class'=>'u-featured'));' - 那看起來好嗎?它似乎工作! – user1406440