首页 文章

Wordpress发布内容布局

提问于
浏览
0

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

所以我在我的头版上有3个最新博客文章的列表,其中显示了“ Headers ”,“摘录”和“更多...”链接, Headers 和更多链接都将您带到single.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>

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

该帖子正在front-page.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; ?>

1 回答

  • 0

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

    <?php if (is_page( page id )){ your query }

    祝好运! ;)

    PS ..或在你的路上:

    <?php if (is_page( page id )): ?> 您的查询 <?php endif; ?>

相关问题