• Hi,

    I have a ctegory page template which is build in this way:

    First Loop = Posts from the current category which have the tag 233

    Second Loop = Posts from the current category which don’t have the tag 233

    The first problem is that the first loop is appearing at the top of all pages (instead of just the first one).

    The second problem is that it suppose to give me 5 posts in every page and it does, but aside from the first loop that is just being add to those 5…

    Here is the code:

    <?php get_header(); ?>
    
    <div id="morim_warper">
    
            <div class="header">
            <h1>
            <?php echo(get_category_parents($cat, TRUE, '&nbsp;')); ?>
    		</h1>
    		<span id="orderBy">??? ??? ??-??<br/><span>??? ?????? ?????</span>
    		</span>
    
            </div>
    		<?php if(function_exists('wp_page_numbers')) { wp_page_numbers(); } ?>
    		<br/>
    		<span id="startPageNumbers">
    
    		<?php
    		 	$categories = get_the_category();
    				$category_id = $categories[0]->cat_ID;
    			//	echo $category_id; // enable this to check what category this is in
    		?>
    
    		<? $the_query = new WP_Query( 'tag_id=233' ); ?>
    		<?php if ( $the_query->have_posts() ) {
    		        echo '<ul>';
    			while ( $the_query->have_posts() ) {
    				$the_query->the_post();
    				if ( in_category( $category_id )) { ?>
    
    					<div class="more">
    							<?php if( has_tag() ) { echo '<img class="starMark" src="https://www.guitara.co.il/wp-content/themes/mguitara/images/starMark.png"/>'; } else { echo ''; } ?>
    							<a href="<?php the_permalink() ?>" rel="bookmark" title="??? ????? ??:
    							<?php the_title_attribute();?>">
    							<img class="teacherIMG" alt="???? ?????? <?php the_title(); ?>"
    							src="https://www.guitara.co.il/images/teachers/<?php echo get_post_meta($post->ID, 'face', true); ?>_teacher.jpg"/>
    							</a>
    
    							<h1>
    							<a href="<?php the_permalink() ?>" rel="bookmark" title="??? ????? ??:
    							<?php the_title_attribute();?>">
    							<?php the_title(); ?>
    							</a>
    							</h1>
    
    					        <p class="fewlines">
    					        <a href="<?php the_permalink() ?>" rel="bookmark" title="??? ????? ??:
    							<?php the_title_attribute();?>">
    							<?php if ( ! has_excerpt() ) {
    					            $experience = get_post_meta($post->ID, 'experience', true);
    					            $guitars = get_post_meta($post->ID, 'guitars', true);
    					            $singlesentence = get_post_meta($post->ID, 'singlesentence', true);
    					            $birthDate =array();
    					$birthDate[] = get_post_meta($post->ID, 'birth_month', true);
    					$birthDate[] = get_post_meta($post->ID, 'birth_day', true);
    					$birthDate[] = get_post_meta($post->ID, 'birth_year', true);
    					$birthDate = array_filter($birthDate);
    					//get age from date or birthdate
    					if(!empty($birthDate)) {
    					$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y")-$birthDate[2])-1):(date("Y")-$birthDate[2]));}
    
    					            echo "???? ?????? $guitars, ?? ????? ?? $experience ????. ???:$age.            $singlesentence.
    					            ";
    					            } else {
    					            the_excerpt();
    					            }?>
    							</a>
    							</p>
    
    							<h2>
    							<b>???? ?????:</b>
    							<?php echo get_post_meta($post->ID, "price", true);?> ?
    							</h2>
    							<h2>
    							<b>?????:</b>
    							<?php echo get_post_meta($post->ID, "area_code", true);?>-<?php echo get_post_meta($post->ID, "phone", true);?>
    							</h2>
    
    					</div><!-- end more -->
    
    				<? } else {
    					// It's not in the category, ignore it
    				}
    			}
    		        echo '</ul>';
    		} else {
    			// no posts found
    			echo '';
    		}
    		?>
    
    		<?php rewind_posts(); ?>
    
    		<?php if (have_posts()) :?>
    		<?php $posts=query_posts($query_string . '&orderby=title&order=asc&tag__not_in=233');
    		      while (have_posts()) : the_post(); ?>
    
    <div class="more">
    		<?php if( has_tag() ) { echo '<img class="starMark" src="https://www.guitara.co.il/wp-content/themes/mguitara/images/starMark.png"/>'; } else { echo ''; } ?>
    		<a href="<?php the_permalink() ?>" rel="bookmark" title="??? ????? ??:
    		<?php the_title_attribute();?>">
    		<img class="teacherIMG" alt="???? ?????? <?php the_title(); ?>"
    		src="https://www.guitara.co.il/images/teachers/<?php echo get_post_meta($post->ID, 'face', true); ?>_teacher.jpg"/>
    		</a>
    
    		<h1>
    		<a href="<?php the_permalink() ?>" rel="bookmark" title="??? ????? ??:
    		<?php the_title_attribute();?>">
    		<?php the_title(); ?>
    		</a>
    		</h1>
    
            <p class="fewlines">
            <a href="<?php the_permalink() ?>" rel="bookmark" title="??? ????? ??:
    		<?php the_title_attribute();?>">
    		<?php if ( ! has_excerpt() ) {
                $experience = get_post_meta($post->ID, 'experience', true);
                $guitars = get_post_meta($post->ID, 'guitars', true);
                $singlesentence = get_post_meta($post->ID, 'singlesentence', true);
                $birthDate =array();
    $birthDate[] = get_post_meta($post->ID, 'birth_month', true);
    $birthDate[] = get_post_meta($post->ID, 'birth_day', true);
    $birthDate[] = get_post_meta($post->ID, 'birth_year', true);
    $birthDate = array_filter($birthDate);
    //get age from date or birthdate
    if(!empty($birthDate)) {
    $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y")-$birthDate[2])-1):(date("Y")-$birthDate[2]));}
    
                echo "???? ?????? $guitars, ?? ????? ?? $experience ????. ???:$age.            $singlesentence.
                ";
                } else {
                the_excerpt();
                }?>
    		</a>
    		</p>
    
    		<h2>
    		<b>???? ?????:</b>
    		<?php echo get_post_meta($post->ID, "price", true);?> ?
    		</h2>
    		<h2>
    		<b>?????:</b>
    		<?php echo get_post_meta($post->ID, "area_code", true);?>-<?php echo get_post_meta($post->ID, "phone", true);?>
    		</h2>
    
    </div><!-- end more -->
    		<?php endwhile; ?>
    		</span><!-- EndPageNumbers -->
    		<?php if(function_exists('wp_page_numbers')) { wp_page_numbers(); } ?>
    </div><!-- end morim_warper -->		
    
    <div id="citylist">
    <h2>
    ??? ???? ????? (??? ???):
    </h2>
    <?php wp_list_categories('child_of=9&title_li='); ?>
    <div id="clear"></div>
    </div><!-- end #citylist -->
    
    <div id="wordsforcityofteachers">
    ????? ??? ????? ????? ???? ?????? <?php echo get_cat_name( $cat ); ?> ??? ????? ????? <?php echo get_cat_name( $cat ); ?> ?????? ????? ???? ?????? ?????? ????? <?php echo get_cat_name( $cat ); ?>. ?? ????? ???? ?????? <?php echo get_cat_name( $cat ); ?> ??? ????? ??? ??????? ????? ??? ????? "??? ???" ??????? ??????. ?? ?? ??? ?????? ?? ???? ?????? <?php echo get_cat_name( $cat ); ?> ??? ????? ????? ?? ???? ?? ????? ??? ??? ???? "??? ???" ?????? ?? ????? (????? ????? ??-????) ??? ????? ????? ???? ??? ?????? ?? ????? ????? ???? ???? ?????? ????? ??.
    ?? ???? ??? ??? ?? ?????? <?php echo get_cat_name( $cat ); ?> ?????? ??????!
    </div>
    
    <div id="googlead1">
    <a href="https://www.guitara.co.il/%D7%94%D7%A6%D7%A2%D7%94-%D7%9C%D7%97%D7%A0%D7%95%D7%99%D7%95%D7%AA-%D7%A0%D7%92%D7%99%D7%A0%D7%94/"><img src="wp-content/themes/mguitara/images/Square.jpg" alt="????? ????????"/></a>
    </div>
    
    <div id="googlead2">
    <?php layerslider(3); ?>
    </div>
    
    	<?php else : ?>
    
    		<h2>?? ????? ??????</h2>
    		<?php include (TEMPLATEPATH .'/searchform.php'); ?>
    
    	<?php endif; ?>
    
    <?php get_footer(); ?><!-- template shel category ????? ?????? + children's -->

    Any ideas?

    Thanks.

    https://www.ads-software.com/plugins/wp-page-numbers/

  • The topic ‘Two Loops Problem’ is closed to new replies.