首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何仅在主页上添加帖子缩略图,并在下划线主题中添加存档

如何仅在主页上添加帖子缩略图,并在下划线主题中添加存档
EN

Stack Overflow用户
提问于 2018-10-20 02:29:12
回答 2查看 123关注 0票数 1

基本上,我只想在主页上添加缩略图图像,但它也显示缩略图图像(特色图像)在单一的内容,我不想加载在单一的页面。

我想像这样添加缩略图:

(来自here )

主题:强调发展主题

我的content.php:

代码语言:javascript
复制
 <?php
/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package DevWP
 */

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <?php
        if ( is_singular() ) :
            the_title( '<h1 class="entry-title">', '</h1>' );
        else :
            the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
        endif;

        if ( 'post' === get_post_type() ) :
            ?>
            <div class="entry-meta">
                <?php devwp_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif; ?>
    </header><!-- .entry-header -->

    <?php devwp_post_thumbnail(); ?>

    <div class="entry-content">
        <?php

        if ( is_single() ) {
        the_content( sprintf(
            wp_kses(
                /* translators: %s: Name of current post. Only visible to screen readers */
                __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'devwp' ),
                array(
                    'span' => array(
                        'class' => array(),
                    ),
                )
            ),
            get_the_title()
        ) );
        } else {
            the_excerpt();
        }

        wp_link_pages( array(
            'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'devwp' ),
            'after'  => '</div>',
        ) );
        ?>
    </div><!-- .entry-content -->

    <footer class="entry-footer">
        <?php devwp_entry_footer(); ?>
    </footer><!-- .entry-footer -->
</article><!-- #post-<?php the_ID(); ?> -->
<hr>
EN

回答 2

Stack Overflow用户

发布于 2018-10-20 03:12:44

我不确定我是否正确理解了你的目标是什么,但如果你想只在主页上显示特色图像,而不是其他页面,那么你可以尝试两件事。在content.php文件中的第一个检查您是否在使用is_front_page()访问主页:

代码语言:javascript
复制
if(is_front_page()){
  devwp_post_thumbnail();// I suppose this is echoing your thumbnail
}

您可以做的第二件事是为不打算输出缩略图的页面创建自定义页面模板。

票数 1
EN

Stack Overflow用户

发布于 2018-10-20 14:14:07

把这个代码..。

代码语言:javascript
复制
if( is_front_page() && is_home() ) {
  devwp_post_thumbnail();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52898093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档