我试图让我的日期和评论计数包含在循环中

时间:2012-10-25 15:46:40

标签: php loops

我正在创建我的第一个wordpress主题(并且第一次真正使用wordpress)。

我正在尝试将我的日期和评论计数包含在循环中,即使我在侧边栏的左边有它,但我无法弄清楚如何包含它。

这是我的帖子代码(它包含日期,评论数量和帖子的顺序,帖子当前只是循环的一部分):

(我正在使用960网格,因此您可能会看到下面的网格类)

<div class="date_banner">
        <div class="d"><!-- sidebar 1 --><?php the_time('d'); ?></div>
        <div class="m"><!-- sidebar 1 --><?php the_time('M'); ?></div>
        <div class="y"><!-- sidebar 1 --><?php the_time('Y'); ?></div>
    </div>
    <div class="commentsnumber">
    <?php comments_number('No comment', '1 comment', '% comments'); ?>
    </div>
    </div>
    <div class="grid_10">

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <!-- post -->
        <div class="post">
            <div class="titlepostauthorimage">
            <div class="post-title">
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </div>
            <div class="post-author-image">

            </div>
            <div class="post-author">
                 <?php the_author_posts_link(); ?>
            </div>
            <div class="post-image">
                <?php the_post_thumbnail( $size, $attr ); ?> 
            </div>
            </div>
            <div class="post-bodyborder">
            <div class="post-body">
                <?php the_content(); ?>
            </div>
            </div>
            <div class="post-metaborder">
            <div class="post-meta">
                <?php the_category(', '); ?>
                <!-- post tags -->
            </div>
            </div>
            <div class="post-comments">
            <?php wp_list_comments( $args ); ?> 
            </div>
        </div>
        <!-- post -->
    <?php endwhile; else: ?>
        <!-- In case no posts were found -->
        <h1>Hmmm? Cam't. Find. Post.</h1>
    <?php endif; ?>

当我将循环移动到测试代码中的日期之上时会发生什么:test

检查员说在第一个grid_10类中,日期和注释计数低于帖子: inspector


这是我完成的主题应该是什么样子 你可以在http://benlevywebdesign.com/wordpress/查看我正在进行的工作(只有帖子在循环中,上面的屏幕截图是我移动循环代码时会发生什么的测试/示例)

theme design

3 个答案:

答案 0 :(得分:1)

它可能会像这样(它只是伪代码)

<div class="container_16" >
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <div class="grid_12" >
           <div class="grid_2"> date banner html goes in here </div>
           <div class="grid_10"> post html goes in here</div>          
        </div>

    <?php endwhile; else: ?>
    <!-- In case no posts were found -->
    <h1>Hmmm? Cam't. Find. Post.</h1>
    <?php endif; ?>
</div>

答案 1 :(得分:0)

要获取发布日期和时间,请使用此

<?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>

要获得评论计数,请使用此

 <?php comments_number('No reply', '1 reply', '% replies'); ?>

放置在循环中的任何位置

价:HTTP://codex.wordpress.org/Function_Reference/comments_number

答案 2 :(得分:0)

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="grid_2">
    <div class="date_banner">
            <div class="d"><!-- sidebar 1 --><?php the_time('d'); ?></div>
            <div class="m"><!-- sidebar 1 --><?php the_time('M'); ?></div>
            <div class="y"><!-- sidebar 1 --><?php the_time('Y'); ?></div>
        </div>
        <div class="commentsnumber">
        <?php comments_number('No comment', '1 comment', '% comments'); ?>
        </div>
    </div>
    <!-- post -->
    <div class="grid_10 post">
        <div class="titlepostauthorimage">
            <div class="post-title">
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </div>
            <div class="post-author-image">

            </div>
            <div class="post-author">
                 <?php the_author_posts_link(); ?>
            </div>
            <div class="post-image">
                <?php the_post_thumbnail( $size, $attr ); ?> 
            </div>
        </div>
        <div class="post-bodyborder">
            <div class="post-body">
                <?php the_content(); ?>
            </div>
        </div>
        <div class="post-metaborder">
            <div class="post-meta">
                <?php the_category(', '); ?>
                <!-- post tags -->
            </div>
        </div>
        <div class="post-comments">
        <?php wp_list_comments( $args ); ?> 
        </div>
    </div>
    <!-- post -->
<?php endwhile; else: ?>
    <!-- In case no posts were found -->
    <h1>Hmmm? Cam't. Find. Post.</h1>
<?php endif; ?>