侧边栏的WordPress内容重复

时间:2019-02-26 09:15:24

标签: php wordpress

我已经为该网站重新创建了一个侧边栏,您可以在此页面上看到它的完美运行-http://dev.thehrdirector.com/features/

但是,如果单击“存档(http://dev.thehrdirector.com/features/archive/),则会看到侧边栏的内容不断重复。我绝对很沮丧,因为两个页面都使用相同的代码。谁能帮我吗?

这是存档页面的代码:

<?php get_header(); ?>

<main role="main" id="article-new">
    <section id="content" class="wrapper">
        <div class="main-col floatleft">
            <div class="title-bar uppercase white brandon">
                <a href="<?php bloginfo('rss2_url'); ?>?post_type=features" title="<?php _e('Syndicate this site using RSS'); ?>" class="floatleft"><img src="<?php echo get_template_directory_uri(); ?>/img/rss-feed.png" alt="RSS Feed" title="RSS Feed" /></a>
                <h1 class="floatleft"><?php _e( 'Features', 'html5blank' ); ?></h1>
                <div class="floatright">
                    More Articles: <a href="<?php echo site_url(); ?>/features" class="white">Latest</a> <a href="<?php echo site_url(); ?>/features-popular" class="white">Popular</a> <a href="<?php echo get_post_type_archive_link( 'features' ); ?>" class="white active">Archives</a>
                </div>
            </div>

            <?php $taxonomy = 'features_categories';
                $terms = get_terms($taxonomy);
                if ( $terms && !is_wp_error( $terms ) ) :
            ?>
                <ul class="archives freight">
                    <?php foreach ( $terms as $term ) { ?>
                        <li><a href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?></a></li>
                    <?php } ?>
                </ul>
            <?php endif;?>
        </div>

        <div class="right-col floatright">
            <?php get_sidebar('article'); ?>
        </div>
    </section>
</main>

这是侧栏的代码:

<aside class="sidebar" role="complementary">
<?php 
    if (have_posts()) : while (have_posts()) : the_post();

        if( have_rows('article_sidebar_content', 'option') ): 

            while ( have_rows('article_sidebar_content', 'option') ) : the_row();

            // LATEST NEWS
            if( get_row_layout() == 'latest_news' )
                get_template_part( 'partials/'. get_row_layout() );

            // ADVERTS
            if( get_row_layout() == 'ads' )
                get_template_part('partials/'. get_row_layout() );

            // LATEST SENIOR HR JOBS
            if( get_row_layout() == 'latest_senior_hr_jobs' )
                get_template_part('partials/'. get_row_layout() );

            // FEATURES
            if( get_row_layout() == 'features' )
                get_template_part( 'partials/'. get_row_layout() );

            // LATEST ROUNDTABLE REPORT
            //LATEST HR DIRECTOR INTERVIEW
            //LEGAL UPDATES
            //BLOG          
            if( get_row_layout() == 'misc' )
                get_template_part( 'partials/'. get_row_layout() );

            endwhile; 
        endif; 

    endwhile; endif; 
?>

1 个答案:

答案 0 :(得分:0)

您可以在边栏中测试wp_reset_query()吗?

<?php 
query_post('post_type=post');
    if (have_posts()) : while (have_posts()) : the_post();

        if( have_rows('article_sidebar_content', 'option') ): 

            while ( have_rows('article_sidebar_content', 'option') ) : the_row();

            // LATEST NEWS
            if( get_row_layout() == 'latest_news' )
                get_template_part( 'partials/'. get_row_layout() );

            // ADVERTS
            if( get_row_layout() == 'ads' )
                get_template_part('partials/'. get_row_layout() );

            // LATEST SENIOR HR JOBS
            if( get_row_layout() == 'latest_senior_hr_jobs' )
                get_template_part('partials/'. get_row_layout() );

            // FEATURES
            if( get_row_layout() == 'features' )
                get_template_part( 'partials/'. get_row_layout() );

            // LATEST ROUNDTABLE REPORT
            //LATEST HR DIRECTOR INTERVIEW
            //LEGAL UPDATES
            //BLOG          
            if( get_row_layout() == 'misc' )
                get_template_part( 'partials/'. get_row_layout() );

            endwhile; 
        endif; 

    endwhile; endif; 
    wp_reset_query();
?>