【问题标题】:Adapting page.php to index.php in Wordpress在 Wordpress 中将 page.php 适配为 index.php
【发布时间】:2015-04-12 14:51:04
【问题描述】:

在“阅读设置”中,我选择了我创建的页面的静态页面下拉菜单作为帖子页面。

我已将page.php 中的html、php 和css 放入index.php 以设置样式。我无法获得特色图片。我用来在 page.php 上获取它的 php 不起作用。它不呈现任何 html。另外<?php the_title(); ?> 正在拉起最近一篇博文的标题,而不是我切换的页面的标题。

这就是我在 page.php 上生成特色图片的方式。

            <div class="single-image-anchor">
                <?php if (has_post_thumbnail( $post->ID ) ): ?>
                <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
                <div class="single-image" style="background-image: url('<?php echo $image[0]; ?>')">
                <?php endif; ?>
            </div>

这是我原来index.php的代码

<?php get_header('header-main'); ?>

    <main role="main">
        <!-- section -->
        <section>

            <h1><?php _e( 'Latest Posts', 'html5blank' ); ?></h1>

            <?php get_template_part('loop'); ?>

            <?php get_template_part('pagination'); ?>

        </section>
        <!-- /section -->
    </main>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

我对 Wordpress 还很陌生,所以在此先感谢。

【问题讨论】:

  • @sdcr 查看编辑。谢谢
  • 添加了 THE POST 的特色图片,非常棒,非常感谢,但我正在尝试添加现在托管博客循环的 PAGE 的特色图片。
  • 刚刚编辑了我的评论,见上文

标签: wordpress settings dynamic-featured-image


【解决方案1】:
             <div class="page-section clear">
                <div class="single-image-anchor">
                <?php if (get_option( 'page_for_posts' ) ): ?>
                <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_option( 'page_for_posts' )), 'single-post-thumbnail' ); ?>
                <div class="single-image" style="background-image: url('<?php echo $image[0]; ?>')">
                <?php endif; ?>
                </div>
            </div>
        <h1 class='title'><?php if(get_option( 'page_for_posts' ) ) echo get_the_title( get_option( 'page_for_posts' ) ); ?> </h2>
        <h1><?php _e( 'Latest Posts', 'html5blank' ); ?></h1>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多