繁体   English   中英

Wordpress home.php重复内容?

[英]Wordpress home.php repeats content?

我是一个Wordpress noob,但试图将我的HTML / CSS主题实现到WP中,但我偶然发现了一个奇怪的错误...每次我添加另一个帖子,home.php页面在页面结束后重复:o这是我的home.php的HTML / PHP代码,它将是我的主页:

<?php 
    get_header();
?>      
        <!-- WRAPPER START -->
        <section id="wrapper">
            <?php 
                if(have_posts()):
                    while(have_posts()):
                        the_post();
            ?>
            <!--  start dynamic part -->
            <!-- NEWS START -->

            <div id="slider">       
                <article>
                    <h2>
                        <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
                    </h2>

                    <p class="m-post-info">
                        Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> on 
                        <?php the_date('d-m-Y'); ?> |
                         <a href="<?php the_permalink();?>"><?php comments_number( 'no comment', 'one comment', '% comments' ); ?></a>
                    </p>

                    <div>
                        <?php the_content(); ?> 
                    </div>

                    <a id="arrow-left" href="#" title="Previous"></a>
                    <a id="arrow-right" href="#" title="Next"></a>
                </article>
            </div>

            <!-- NEWS END -->


            <!-- MAIN CONTENT START-->

            <section id="main-content">


                <!-- 3COLUMN LAYOUT START -->

                <div id="column-1">
                    <h3>
                        POPULAR ARTICLES
                    </h3>
                    <article class="news-article">
                        <header>
                            <h4>
                                 <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
                            </h4>
                            <p class="post-info">
                                Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> |  <a href="<?php the_permalink();?>"><?php comments_number( 'no comment', 'one comment', '% comments' ); ?></a>
                            </p>
                        </header>
                        <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" />
                        <div class="post-text">
                             <?php the_excerpt(); ?>
                        </div>
                    </article>
                    <article class="news-article">
                        <header>
                            <h4>
                                 <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
                            </h4>
                            <p class="post-info">
                                Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> |  <a href="<?php the_permalink();?>"><?php comments_number( 'no comment', 'one comment', '% comments' ); ?></a>
                            </p>
                        </header>
                        <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" />
                        <div class="post-text">
                             <?php the_excerpt(); ?>
                        </div>
                    </article>
                </div>

                <div id="column-2">
                    <h3>
                        RECENT COMMENTS
                    </h3>

                    <div class="comment">
                        <?php
                        $comments = get_comments('status=approve&number=3');
                          foreach($comments as $comment) :?>
                          <?php $my_id = $comment->comment_post_ID ; $post_id_comms = get_post($my_id); $title = $post_id_comms->post_title;?> 
                        <p class="user">
                            <?php echo($comment->comment_author);?> <span class="text-decoration">says</span><br />
                           </p>
                         <p class="user-text">
                            <?php echo($comment->comment_content);?><br />
                        </p>
                        <?php endforeach;?>
                    </div>
                </div>

                <div id="column-3">
                    <h3>
                        LIFESTREAM
                    </h3>
                    <article class="news-article">
                        <header>
                            <h4>
                                 <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
                            </h4>
                            <p class="post-info">
                                Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> |  <a href="<?php the_permalink();?>"><?php comments_number( 'no comment', 'one comment', '% comments' ); ?></a>
                            </p>
                        </header>
                        <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" />
                        <div class="post-text">
                             <?php the_excerpt(); ?>
                        </div>
                    </article>
                    <article class="news-article">
                        <header>
                            <h4>
                                 <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
                            </h4>
                            <p class="post-info">
                                Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> |  <a href="<?php the_permalink();?>"><?php comments_number( 'no comment', 'one comment', '% comments' ); ?></a>
                            </p>
                        </header>
                        <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" />
                        <div class="post-text">
                             <?php the_excerpt(); ?>
                        </div>
                    </article>
                </div>

                <!-- 3COLUMN LAYOUT END -->

                <!-- SIDEBAR START -->

                <aside id="tab-lists">
                    <?php if(!dynamic_sidebar('telerik-sidebar')): ?>
                    <div>
                        <h5 id="tab1">
                            <span>recent posts</span>
                        </h5>
                        <ul>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                        </ul>
                    </div>
                    <?php endif; ?>
                    <?php if(!dynamic_sidebar('telerik-sidebar2')): ?>
                    <div>
                        <h5 id="tab2">
                            <span>recent posts</span>
                        </h5>

                        <ul>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                            <li>
                                <a href="#">Pellentesque tincidunt, diam eget accumsan</a>
                            </li>
                        </ul>
                    </div>
                    <?php endif; ?>
                </aside>    

                <!-- SIDEBAR END -->

                <!-- BIG POST START -->
                <div id="big-post">
                    <h3>
                        RECENT POSTS
                    </h3>
                    <article>
                        <header>
                            <h2>
                                <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
                            </h2>
                            <p class="post-info">
                                Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> | <a href="<?php the_permalink();?>"><?php comments_number( 'no comment', 'one comment', '% comments' ); ?></a>
                            </p>
                        </header>
                        <img src="<?php echo get_template_directory_uri() ?>/images/image-big.png" alt="Picture" title="Example Image 2" width="214" height="214" />
                        <div class="post-text">
                            <?php the_content(); ?>  
                        </div>
                    </article>
                </div>
                <!-- BIG POST END -->

            </section>

            <!-- MAIN CONTENT END -->
        <!-- END DYNAMIC PART -->
            <?php 
                endwhile;
                endif;
            ?>
        </section>

        <!-- WRAPPER END -->

<?php 
    get_footer();
?>

你已经(几乎)整个页面都在循环中 ,因此对于每个帖子,它将重复所有内容。
在您想结束帖子后关闭片刻, while不是在页面末尾。

你需要在以下之后停止它: <!-- NEWS END -->

我不明白你的意思是重复它自己。

<article class="news-article">
    <header>
        <h4>
            <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
        </h4>
        <p class="post-info">
            Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> |  <a href="<?php the_permalink();?>"><?php comments_number( 'no comment', 'one comment', '% comments' ); ?></a>
        </p>
    </header>
    <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" />
    <div class="post-text">
        <?php the_excerpt(); ?>
    </div>
</article>
<article class="news-article">
    <header>
        <h4>
            <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
        </h4>
        <p class="post-info">
            Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> |  <a href="<?php the_permalink();?>"><?php comments_number( 'no comment', 'one comment', '% comments' ); ?></a>
        </p>
    </header>
    <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" />
    <div class="post-text">
        <?php the_excerpt(); ?>
    </div>
</article>

在我看来,你应该只有一次这个代码部分:

<article class="news-article">
    <header>
        <h4>
            <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
        </h4>
        <p class="post-info">
            Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> |  <a href="<?php the_permalink();?>"><?php comments_number( 'no comment', 'one comment', '% comments' ); ?></a>
        </p>
    </header>
    <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" />
    <div class="post-text">
        <?php the_excerpt(); ?>
    </div>
</article>

我在模板中这样做,但我仍然没有完全解决问题。

仔细看看你必须尝试做多个循环。 每个应该不止一次的部分或者你想看到你的帖子需要一个循环。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM