1

问题如上。我正在尝试在不是标题图像的用户生成内容上方生成自定义图像。我用 ACF 做这个。预期结果显示在 page.php 生成的页面上,但不在客户端站点用作帖子页面的 index.php 上。

尝试将代码放置在任何可以想象的地方。Wordpress 调试并且只写 TEST 这个词表明我的定位和文件不正确。

    <header class="page-header">

“ 风格=”显示:块;边距:自动;margin-bottom: 10px;"/> //相关ACF代码显示在page.php文件生成的页面上没有问题

        <h1 class="page-title"><?php single_post_title(); ?></h1>
    </header>
<?php else : ?>

<header class="page-header">
    <h2 class="page-title"><?php _e( 'Posts', 'twentyseventeen' ); ?></h2>
</header>
<?php endif; ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

        <?php
        if ( have_posts() ) :

            /* Start the Loop */
            while ( have_posts() ) :
                the_post();

                /*
                 * Include the Post-Format-specific template for the content.
                 * If you want to override this in a child theme, then include a file
                 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                 */
                get_template_part( 'template-parts/post/content', get_post_format() );

            endwhile;

            the_posts_pagination(
                array(
                    'prev_text'          => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
                    'next_text'          => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
                    'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
                )
            );

        else :

            get_template_part( 'template-parts/post/content', 'none' );

        endif;
        ?>

    </main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>

什么都没有出现。没有错误信息。可以在 Wordpress CMS 的帖子页面上将预期的图像上传到 ACF,但保存时不显示。

4

1 回答 1

1

来自文档https://www.advancedcustomfields.com/resources/value-loading-posts-page/。我假设您已将其设置为返回图像的 URL。

<?php 
$imageUrl = get_field('image-head', get_option('page_for_posts'));

if( !empty($imageUrl) ): ?>

    <img src="<?php echo $imageUrl;?>" />

<?php endif; ?>

索引页面上的查询是博客文章而不是页面,因此您必须明确告诉 ACF 您想要页面中的字段(其他存档页面也是如此)。

于 2019-07-25T06:51:07.983 回答