【发布时间】:2023-03-29 16:14:01
【问题描述】:
我正在更新我的 loop.php 中的类,并且除了图像类之外,我已经设法完成了这一切。除此之外,我还想包含一个默认占位符图像,如果没有更新图像,则会显示该图像。有人可以帮忙吗?
这是我目前的 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",要更改吗?还是加进去? -
它实际上是
img标签上的类,而不是链接。但是,我想我可以通过在末尾添加另一个数组来做到这一点:the_post_thumbnail(array(120,120),array('class' => 'u-featured'));- 看起来可以吗?它似乎工作!
标签: php wordpress wordpress-theming