• I have a category page template for all categories under a specific parent category which look’s like that:

    <?php get_header(); ?>
    
    <div id="morim_warper">
    
            <div class="header">
            <h1>
            <?php echo(get_category_parents($cat, TRUE, ' ')); ?>
    		</h1>
    		<span id="orderBy">לפי סדר א׳-ב׳<br/><span>פרט לקידום ממומן</span>
    		</span>
    
            </div>
    		<?php if(function_exists('wp_page_numbers')) { wp_page_numbers(); } ?>
    		<br/>
    
    		<?php if (have_posts()) :?>
    		<?php $posts=query_posts($query_string . '&orderby=title&order=asc');
    		      while (have_posts()) : the_post(); ?>
    
    <div class="more">
    		<?php if( has_tag() ) { echo '<img class="starMark" src="http://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="http://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; ?>
    
    		<?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="http://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 -->

    Now the idea is simple it’s giving me a list of posts from that sub category, but now i want to add at the top of the list posts that have a specific tag with in that current sub category and after that the regular loop for the other posts (that don’t have this tag.

    I was trying reading all the different posts about “multiple loops” but couldn’t make it… I dont really know php, i mostly copy and past code and it works in the end 🙂

    If some one could show me how to that in my specific case it would be great!!!

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter Begin

    (@bentalgad)

    I have got this working now with that 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="http://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="http://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="http://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="http://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="http://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 -->

    But the problem is that the first loop and the second loop dosent count together so instead of having 5 posts in every page it adds the first loop to the top of any page beside the second loop 5 pages…

    Any ideas?

Viewing 1 replies (of 1 total)
  • The topic ‘Two loops on a category page’ is closed to new replies.