【发布时间】:2015-10-14 03:10:42
【问题描述】:
在我的 wordpress 主题中,我使用函数在我的 index.php 中显示帖子的第一张图片
对我来说,我不想在我的主题中添加支持缩略图。它太烦人了!
我观看了一个教程,该教程教如何通过为摘录添加一个 padding-left 并将图像浮动到左侧以使图像在左侧和摘录中,从而在帖子摘录的左侧显示图像在图像旁边。此外,本教程还教您如何在帖子没有图片时不执行任何操作(不执行任何操作=不推送摘录并且不向图像添加浮动,以便帖子的格式看起来正常)。
他通过使用函数 if has_post_thumbnail = 做某事(在摘录中添加一个 padding-left 并在右侧浮动图像)并且如果帖子没有 thumbnail = 什么也不做。就是这样。
代码如下:
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="post <?php if ( has_post_thumbnail() ) { ?>has-thumbnail <?php } ?>">
<!-- post-thumbnail -->
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('small-thumbnail'); ?></a>
</div><!-- /post-thumbnail -->
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="post-info"><?php the_time('F j, Y g:i a'); ?> | by <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>">
现在我想做同样的事情,但我不想在我的主题中添加对缩略图的支持,而且我不打算支持缩略图。
我尝试将 has_post_thumbnail() 替换为我使用的 get post first image 函数,但没有成功。
我真的需要在我的网站上这样做。那请问各位大侠有什么解决办法吗?
【问题讨论】:
-
为了避免使用帖子缩略图而进行黑客攻击将比首先启用它们(这涉及在 functions.php 中添加一行)更多的工作
标签: php html css wordpress image