【问题标题】:How to move the featured image below the title in Marketify single post如何在 Marketify 单个帖子中将特色图片移动到标题下方
【发布时间】:2017-02-09 12:23:35
【问题描述】:

我正在尝试将帖子的特色图片移动到 Marketify 主题中帖子标题的下方,但我似乎无法在代码中找到它。

谁能帮我找到帖子特色图片的代码?如何将其移至帖子标题下方?

【问题讨论】:

  • 这取决于主题开发者如何称呼他们的模板文件。首先,您的主题目录中是否有一个名为“single.php”的文件?通常,在 '/wp-content/themes/[theme-name]

标签: php wordpress post themes blogs


【解决方案1】:

首先,为您的 WordPress 主题创建一个Child Theme

然后查看“/wp-content/themes/[theme-name]”,您应该在其中找到一个名为“single.php”的文件。将此复制到您的子主题中,注意确保您复制相同的目录层次结构。 “single.php”通常是您的默认博客文章模板的名称。

使用 Notepad++ 之类的程序打开您保存在子主题中的“single.php”文件(记事本也可以,但看起来不那么容易)。

您应该会看到如下内容:

    <?php if ( has_post_thumbnail() ) {
        the_post_thumbnail();
    }?>
    <?php 
    if (have_posts()) : 
        while (have_posts()) : the_post(); ?>

            <h1><?php the_title(); ?></h1>  //This is the title of your Blog Post. 

            <div class="entry">
            <?php the_content(); ?> //This is the content of your Blog Post.
            </div>

        <?php endwhile; ?>  
    <?php endif; ?>

编码会有细微的变化,但您要做的是突出显示:

<?php if ( has_post_thumbnail() ) {
        the_post_thumbnail();
}?>

然后将此编码移至&lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt; 下方。您将需要在哪里需要它,但我希望这可以帮助您入门。

我建议您在子主题中执行此操作的原因是,当主题开发人员推出更新时,它将删除您在父文件中所做的任何修改。

祝你好运!

【讨论】:

    【解决方案2】:

    感谢您的评论。我认为它也与您编写的代码相似,但标题和特色图片隐藏在“do_action('marketify_entry_before');”中。

        get_header(); ?>
    
        <?php do_action( 'marketify_entry_before' ); ?>
    
        <div class="container">
        <div id="content" class="site-content row">
    
            <div role="main" id="primary" class="col-xs-12 col-md-8 <?php echo ! is_active_sidebar( 'sidebar-1' ) ? 'col-md-offset-2' : '' ?>">
                <main id="main" class="site-main" role="main">
    
                <?php if ( have_posts() ) : ?>
    
                    <?php while ( have_posts() ) : the_post(); ?>
    
                        <?php get_template_part( 'content', 'single' ); ?>
                        <?php comments_template(); ?>
    
                    <?php endwhile; ?>
    

    不过,对于遇到同样问题的其他人来说;我想出了如何像这样在 css 中隐藏此部分...

        .single .header-outer.has-image .page-header {
            display: none;
        }
    

    然后可以使用标准的 Wordpress 功能使标题和特色图片出现在我想要的位置。

    谢谢:)

    汤姆

    【讨论】:

      猜你喜欢
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      • 2015-04-24
      • 1970-01-01
      相关资源
      最近更新 更多