修改twentytwelve默认缩略图

1 星2 星3 星4 星5 星 (觉着不错就5星评价哦)

Twentytwelve默认缩略图真是太丑,不仅体积大不说,而且在上方,真是看起来相当的不爽。找了许久,找到一个相当简单的方法修改缩略图的功能。

编辑Functions.php

编辑functions.php,找开后找到如下代码

function twentytwelve_setup() {
load_theme_textdomain( 'twentytwelve', get_template_directory() . '/languages' );
add_editor_style();
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) );
add_theme_support( 'custom-background', array(
'default-color' => 'f2f2f2',
) );
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 624, 9999 );

在此这后加上一段代码

// 增加140x140缩略图
add_image_size('excerpt-thumbnail', 140, 140, true);

编辑content.php

在 content.php中找到如下代码

<div class="entry-summary">

在此之后加上如下代码

<!-- 增加140x140缩略图 -->
<div class="excerpt-thumb">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php the_post_thumbnail('excerpt-thumbnail', 'class=alignleft'); ?>
</a>
</div><!-- excerpt-thumb -->

此时就差不多了,但是还完善,因为这样还会默认显示原来的缩略图。

继续完善

在content.php中找到如下代码删掉

<?php the_post_thumbnail(); ?>

页面添加缩略图

经过上面的步骤,基本上是首页显示缩略图了。如果想在页面也显示缩略图该怎么办?

继续编辑content.php,找到如下代码

<div class="entry-content">

在此代码下面添加如下代码

<!-- 页面增加140x140缩略图 -->
<div class="excerpt-thumb">
<?php the_post_thumbnail('excerpt-thumbnail', 'class=alignleft'); ?>
</div>

好了,保存刷新看看吧。

当然上面的所有缩略图都可以修改,按照自己喜欢尺寸修改即可,还可以控制位置。

参考Display Excerpts in Twenty Twelve Theme

本博客文章如未特别说明,皆默认采用署名-相同方式共享 4.0 国际协议

相关文章

发表评论

您的电子邮箱地址不会被公开。