2023-08-28

专业提示:掌握 WordPress 2.9 中新的“后缩略图”功能

专业提示:掌握 WordPress 2.9 中新的“后缩略图”功能

在 WordPress 2.9 发布之前,为您的博客设置“后图像”支持是一项比实际需要的任务更加繁琐的任务。幸运的是,这不再是问题。我将在这个四分钟的视频快速提示中向您展示如何进行设置。

第 1 步:编辑 Functions.php 页面

// Enable support for post-thumbnails

add_theme_support('post-thumbnails');

// If we want to ensure that we only call this function if
// the user is working with WP 2.9 or higher,
// let's instead make sure that the function exists first

if ( function_exists('add_theme_support') ) {
	add_theme_support('post-thumbnails');
}
登录后复制

第 2 步:将图像标签插入循环

在“if have_posts()”循环中,只需将这段代码放置在您喜欢的任何位置即可。此时,WordPress 将相应地在页面上插入图像标签。请注意,您将有权访问“wp-post-image”类,然后您可以使用该类来设置图像的格式/样式。

<?php the_post_thumbnail(); ?>
登录后复制
  • 在 Twitter 上关注我们,或订阅 Nettuts+ RSS Feed 以获取网络上最好的 Web 开发教程。

以上就是专业提示:掌握 WordPress 2.9 中新的“后缩略图”功能的详细内容,更多请关注php中文网其它相关文章!

https://www.php.cn/faq/599221.html

发表回复

Your email address will not be published. Required fields are marked *