WordPress帖子内容布局


Wordpress Post content layout

我正在从头开始构建一个自定义主题,遇到了一个小问题,我需要一些帮助。

所以我的首页列出了3篇最新的博客文章,显示了"标题","摘录"和"更多......"标题和更多链接的链接将您带到单.php。

我正在一个名为"content-post.php"的文件中生成帖子内容,如下所示:

<div class="clearfix">
    <?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?>
    <header class="title">
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    </header>
    <ul class="info">
        <li><?php the_category(', '); ?> | <?php the_time('F Y'); ?></li>
        <!--<li>Written By: <a href="<?php bloginfo('siteurl') ?>/about/"><?php the_author(); ?></li>-->
    </ul>
    <div class="excerpt">
        <p><?php if(is_single()): ?>
            <?php the_content(); ?>
            <?php comments_template(); ?>
        <?php else: ?>
            <?php the_excerpt(); ?>
            <a class="post-link" href="<?php the_permalink(); ?>">More...</a></p>
        <?php endif; ?>
    </div>
</div>

这会将帖子构建到首页.php很好。当您进入使用相同的帖子内容且布局相同的博客页面时,我遇到了问题。有没有办法指定它在首页上的显示方式以及在博客页面上的显示方式?

该帖子显示在首页上.php如下所示:

<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', 'post' ); ?>
<?php endwhile; endif; ?>

在博客页面上,像这样:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'content', 'post' ); ?>

    <?php endwhile; else: ?>
    <p>There are no posts to display or pages here</p>
    <?php endif; ?>

如果我理解你的问题,试试这个:

<?php if (is_page(页面 ID )){查询}

祝你好运!;)

PS.. 或在路上:

<?php if (is_page(页面 ID )): ?> 您的查询 <?php endif; ?>