ugrás a tartalomhoz

lekérdezés megváltoztatása

vadasy · 2014. Szep. 12. (P), 20.15
WP-ben egy oldal sablonmintát szeretnék módosítani, úgy hogy ne az összeset kérdezze le, hanem csak az általam kiválasztottakat, pl.: 5-10 elemet. Az alapprobléma, hogy az oldalon az étlapnál és az itallapnál is megjelenik minden elem (ételek, italok is).

page.template.menu.php
  1. <?php   
  2. /* 
  3.  * Template Name: Menu Page 
  4.  */  
  5. get_header(); ?>  
  6.   
  7.   
  8.   
  9. <?php //$temp_query = $wp_query; ?>  
  10.   
  11. <!-- begin main -->  
  12. <section class="main menulist block grid4 clearfix">  
  13.       
  14.       
  15.   
  16.   
  17.   
  18.     <?php if (have_posts()) : while (have_posts()) : the_post(); ?>  
  19.   
  20.     <header>  
  21.         <h2 class="post-title"><?php the_title(); ?></h2>  
  22.     </header>  
  23.   
  24.     <div class="post-content">  
  25.         <?php the_content() ?>  
  26.     </div>  
  27.   
  28.     <?php endwhileendif;?>  
  29.   
  30.       
  31.   
  32.   
  33.     <?php  
  34.   
  35. // get initial categories  
  36. $categories = get_terms( 'menus'array'orderby' => 'name''order' => 'ASC''hierarchical'  => true, 'parent'=>0, 'hide_empty'    => false, ) );  
  37.   
  38.   
  39. foreach ( $categories as $category ) {  
  40.   
  41. // we don't want child categories now, and since get_categories does not support 'depth' parameter, we use ->parent check  
  42. if ( $category->parent > 0 ) {  
  43.     continue;     
  44. }  
  45.   
  46. $i = 0;  
  47. echo '<h2 class="menu-title level-1">' . $category->name . '</h2>';  
  48. query_posts(  
  49.     array(  
  50.         'menus' => $category->slug,  
  51.         'post_type'=> 'menu-item',  
  52.         //'orderby'=> 'menu_order',  
  53.         'posts_per_page' => -1  
  54.     )  
  55. );  
  56.   
  57.   
  58. if ( have_posts() ) : while (have_posts()): the_post(); global $post;  
  59.   
  60.     // let's make sure that the post is not also in any of child categories, if it is, skip it ( we don't want to display it twice )  
  61.     $child_categories = get_term_children( $category->term_id, 'menus' );  
  62.   
  63.     //if ( $child_categories && in_category( $child_categories, $post->ID ) ) {  
  64.     if ( $child_categories && !is_object_in_term( $post->ID, 'menus'$category->name ) ) {  
  65.         continue;  
  66.     }  
  67.   
  68.     echo 0 === $i ? '' : '';  
  69.     //include 'part.menuitem.php';  
  70.     get_template_part( 'part.menuitem' );  
  71.     $i++;  
  72.   
  73.   
  74. endwhile;  
  75. //wp_reset_query();  
  76. endif;  
  77.   
  78. echo '';  
  79.   
  80. // now, after we listed all the posts, we query for child categories  
  81. $categories2 = get_terms(  
  82.     'menus',  
  83.     array(  
  84.         'parent' => $category->term_id,  
  85.         'hierarchical'  => true,  
  86.     )  
  87. );  
  88.   
  89.   
  90. foreach ( $categories2 as $category ) {  
  91.   
  92.     $j = 0;  
  93.     echo '<h2 class="menu-title level-2">' . $category->name . '</h2>';  
  94.     $posts2 = query_posts(  
  95.         array(  
  96.             'menus' => $category->slug,  
  97.             'post_type'=> 'menu-item',  
  98.             'posts_per_page' => -1  
  99.         )  
  100.     );  
  101.   
  102.     if ( have_posts() ) :while (have_posts()): the_post(); global $post;  
  103.   
  104.         echo 0 === $j ? '' : '';  
  105.         //include 'part.menuitem.php';  
  106.         get_template_part( 'part.menuitem' );  
  107.         $j++;  
  108.     endwhile;  
  109.     //wp_reset_query();  
  110.     endif;  
  111.   
  112.     echo null === $posts2 ? '' : '';  
  113.   
  114. }  
  115.   
  116. echo null === $posts ? '' : '';  
  117.   
  118. }  
  119.   
  120. ?>  
  121.   
  122.   
  123.   
  124.   
  125.   
  126.       
  127. </section>  
  128. <!-- end main -->  
  129.   
  130.   
  131. <?php //$wp_query = $temp_query; ?>  
  132.   
  133.   
  134. <?php get_footer(); ?>