• If you go to this page you’ll see what I am talking about.
    https://stage.kantarvideo.com/category/mentions/

    I only want the sidebar to appear one time which is next the newest post. However it repeats itself after each post. I know it probably has to do with the way I’ve set up the HTML but I’m not sure the best way to go about changing that. I’m not experienced in PHP, is there a script that I can use that will only show the sidebar one time? Below is the code I am using for this page. Any help is appreciated. Thanks!

    <?php get_header(); ?>
     <h1><? the_category(', ')?></h1>
    
    	<? if(have_posts()){
    		while(have_posts()){the_post();
    			if(in_category(get_cat_id('News'))){?>
    			<h1>News</h1>
    			<div class="main-holder">
    				<div class="twocolumns">
    					<div class="data">
    						<p><? the_time('M j, Y')?></p>
    					</div>
    					<div class="text-news">
    						<h2><? the_title()?></h2>
    						<? the_content()?>
    					</div>
    				</div>
    			</div>
    			<? } else {?>
    
    			<div class="main-holder">
    				<div class="inner">
    					<div class="content">
    						<div class="blog-post">
    							<div class="box-title">
    								<div class="txt">
    									<p><? the_time('M j, Y')?></p>
    								</div>
    							</div>
    							<div class="blog-text">
                                <h2><? the_title()?></h2>
    								<? if(has_post_thumbnail()){?>
    								<div class="image">
    									<? the_post_thumbnail()?>
    								</div>
    								<? }?>
    								<? the_content()?>
    								<div class="txt-inf">
    									<span>Posted in</span>
    									<ul>
    										<li><? the_category(', ')?></li>
    									</ul>
    								</div>
    								<div class="share-list">
    							         <div class="sharethis">
     						               <!-- AddThis Button BEGIN -->
                    							<div class="addthis_toolbox addthis_default_style">
                    								<a href="https://www.addthis.com/bookmark.php?v=250&username=xa-4be34fd865544a7b" class="addthis_button_compact">Share</a>
    									            <span class="addthis_separator">|</span>
    								                <a class="addthis_button_facebook"></a>
    								                <a class="addthis_button_myspace"></a>
    								                <a class="addthis_button_google"></a>
    								                <a class="addthis_button_twitter"></a>
    							                </div>
                    					<script type="text/javascript" src="https://s7.addthis.com/js/250/addthis_widget.js#username=xa-4be34fd865544a7b"></script>
    				                	<!-- AddThis Button END -->
                						</div>
    								</div>
    								<div class="box-inform">
    								<? comments_template()?>
    								</div>
    							</div>
    						</div>
    					</div>
    					<?php include (TEMPLATEPATH . '/sidebar-news.php'); ?>
    				</div>
    			</div>
    			<? }?>
    		<? }?>
    
    	<? }?>
    <?php get_footer(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator t-p

    (@t-p)

    In your code, reference to sidebar appears twice, see if that’s what causing the issue:

    <?php include (TEMPLATEPATH . '/<strong>sidebar-news.php</strong>'); ?>
    				</div>
    			</div>
    			<? }?>
    		<? }?>
    	<? } else {?>
    		<div class="main-holder">
    			<div class="blog">
    				<div class="content">
    					<h1>Not found</h1>
    					<p>Sorry, but you are looking for something that isn't here.</p>
    				</div>
    				<? <strong>get_sidebar</strong>()?>
    Thread Starter efranklin002

    (@efranklin002)

    I’ve edited the code to remove that last instance of the sidebar but it is still repeating. Any other ideas on what I could do to prevent it from repeating? thanks

    umm..you’ve put your sidebar in the loop. You should take it outside the loop. You’ll have to put your category conditionals outside the loop as well but your sidbar is being included for every single item in the loop (each post).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘My sidebar is repeating and I don't want that’ is closed to new replies.