word.php上的多个帖子在wordpress上

时间:2017-02-24 12:36:05

标签: php wordpress post

这是我的single.php页面。循环似乎没问题,但它显示所有帖子而不是一个(单个)。这有什么不对吗?

<?php get_header(); ?>
<main class="main-single-post">
    <div class="center">
        <div class="bp1-col-1-1 main-section">
            <div class="main-posts">
                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                <div class="single-post">
                    <nav class="post-navigation">
                        <a href="#">xx</a>
                        <a href="#">Gry</a>
                        <a href="#">ss</a>
                    </nav>
                    <a class="single-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                    <div class="single-post-image" style="background-image:url('<?php echo wp_get_attachment_url( get_post_thumbnail_id() );?>')"></div>
                    <div class="single-post-info">
                        <a class="post-author" href="<?php echo get_author_posts_url(get_the_author_meta('ID')) ?>"><?php the_author(); ?></a>
                        <a class="post-date" href="<?php the_time('j F Y'); ?>"><?php the_time('j F Y'); ?></a>
                        <div class="post-comment-box" href="#">
                            <img class="comment-icon" src="<?php echo get_bloginfo('template_url') ?>/images/comment-icon.png" alt="">
                            <a class="post-comments" href="#">5 komentarzy</a>
                        </div>
                    </div>
                    <div class="single-post-content">
                        <p><?php echo get_post_field('post_content', $id); ?></p>
                    </div>
                    <div class="post-tags">
                        <?php the_tags ('<p class="post-tags-title">Tagi:</p>', ' ', ''); ?>
                    </div>
                    <div class="post-share">
                        <p class="post-share-title">Podziel się ze znajomymi:</p>
                        <div class="social-buttons">
                            <a class="button social-button facebook-button" href="#">
                                <i class="fa fa-facebook" aria-hidden="true"></i>
                                Like
                            </a>        
                            <a class="button social-button twitter-button" href="#">
                                <i class="fa fa-twitter" aria-hidden="true"></i>
                                Tweet
                            </a>
                            <a class="button social-button google-button" href="#">
                                <i class="fa fa-google-plus" aria-hidden="true"></i>
                                +1
                            </a>
                        </div>
                    </div>
                </div>
                <?php endwhile; ?>
                <?php endif; ?>
            </div>
            <div class="sidebar">
                <div class="widget facebook">
                    <div class="fb-page" data-href="https://www.facebook.com/techkillerpl" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true">
                        <blockquote cite="https://www.facebook.com/techkillerpl" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/techkillerpl">TechKiller.pl</a></blockquote>
                    </div>
                </div>
                <div class="widget youtube">
                    <img class="youtube-logo" src="<?php echo get_bloginfo('template_url') ?>/images/widget-youtube-logo.png" alt="">
                    <a class="button button-widget" href="#">
                        Przejdź do strefy
                        <img class="button-arrow" src="<?php echo get_bloginfo('template_url') ?>/images/button-arrow.png" alt="Czytaj więcej">
                    </a>
                </div>
                <div class="widget trusted-us">
                    <div class="button button-widget">Zaufali nam</div>
                    <div id="trusted-us-slider" class="owl-carousel">
                        <img class="brand-logo" src="<?php echo get_bloginfo('template_url') ?>/images/cdp-icon.png" alt="">
                        <img class="brand-logo" src="<?php echo get_bloginfo('template_url') ?>/images/cdp-icon.png" alt="">
                        <img class="brand-logo" src="<?php echo get_bloginfo('template_url') ?>/images/cdp-icon.png" alt="">
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>

1 个答案:

答案 0 :(得分:-1)

you need use 

// Start the loop.
        while ( have_posts() ) : the_post();

            /*
             * Include the post format-specific template for the content. If you want to
             * use this in a child theme, then include a file called called content-___.php
             * (where ___ is the post format) and that will be used instead.
             */
            get_template_part( 'content', get_post_format() );

endwhile;