2012-09-05 2 views
4

내 Wordpress 추천 기사에 슬라이더를 사용합니다. 사용자 정의 카테고리를 선택하고 설정된 양의 게시물을 반환합니다.내 코드를 사용하여 배열의 2 쿼리

사용자 정의 된 첫 번째 게시물은 어떻게 표시합니까? 슬라이더 코드 에 특정 게시물의 ID를 직접 추가하면 해당 게시물이 먼저으로 나타나고 원래 쿼리에서 반환되는 다른 게시물이 계속 표시됩니까?

예를 들어, 페이지의 첫 번째 게시물은 ID 6 (소스 코드로 직접 작성)이고 두 번째, 세 번째 및 네 번째 게시물은 원래 코드의 쿼리에서 반환 된 게시물입니다. 이것이 어떻게 가능한지?

누군가는 이것이 매우 간단하다고 제안했는데, 내가해야 할 일은 커스텀 포스트를 얻기 위해 다른 쿼리를 만든 다음 쿼리를 닫고 다시 열어 다음 쿼리를 얻습니다 (슬라이더 코드에 있음) 마지막으로 항목을 함께 배열로 밀어 넣습니다. PHP에 대한 나의 아주 제한된 지식은 어떻게하는지 이해하지 못하게합니다.

내가 정의 게시물을 얻는 방법을 알고,이 코드는 작동합니다

<?php 
$post_id = 6; 
$queried_post = get_post($post_id); 
?> 

을하지만, 나는 배열로 원래 쿼리를 추가하는 방법을 모르겠어요. ? 회신하도록 선택하는 경우

<?php 
    $responsive = 'on' != get_option('henrik_responsive_layout') ? false : true; 
    $featured_auto_class = ''; 
    if ('on' == get_option('henrik_slider_auto')) $featured_auto_class .= ' et_slider_auto et_slider_speed_' . get_option('henrik_slider_autospeed'); 
?> 
<div id="featured" class="<?php if ($responsive) echo 'flexslider' . $featured_auto_class; else echo 'et_cycle'; ?>"> 
    <a id="left-arrow" href="#"><?php esc_html_e('Previous','henrik'); ?></a> 
    <a id="right-arrow" href="#"><?php esc_html_e('Next','henrik'); ?></a> 

<?php if ($responsive) { ?> 
    <ul class="slides"> 
<?php } else { ?> 
    <div id="slides"> 
<?php } ?> 
     <?php global $ids; 
     $ids = array(); 
     $arr = array(); 
     $i=0; 

     $featured_cat = get_option('henrik_feat_cat'); 
     $featured_num = (int) get_option('henrik_featured_num'); 

     if (get_option('henrik_use_pages') == 'false') query_posts("showposts=$featured_num&cat=".get_cat_ID($featured_cat)); 
     else { 
      global $pages_number; 

      if (get_option('henrik_feat_pages') <> '') $featured_num = count(get_option('henrik_feat_pages')); 
      else $featured_num = $pages_number; 

      query_posts(array 
          ('post_type' => 'page', 
          'orderby' => 'menu_order', 
          'order' => 'ASC', 
          'post__in' => (array) get_option('henrik_feat_pages'), 
          'showposts' => (int) $featured_num 
         )); 
     } ?> 
     <?php if (have_posts()) : while (have_posts()) : the_post(); 
     global $post; ?> 
     <?php if ($responsive) { ?> 
      <li class="slide"> 
     <?php } else { ?> 
      <div class="slide"> 
     <?php } ?> 
       <?php 
       $width = $responsive ? 960 : 958; 
       $height = 340; 
       $small_width = 95; 
       $small_height = 54; 
       $titletext = get_the_title(); 

       $thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,false,'Featured'); 

       $arr[$i]['thumbnail'] = get_thumbnail($small_width,$small_height,'',$titletext,$titletext,false,'Small'); 
       $arr[$i]['titletext'] = $titletext; 

       $thumb = $thumbnail["thumb"]; 
       print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, ''); ?> 
       <div class="featured-top-shadow"></div> 
       <div class="featured-bottom-shadow"></div> 
       <div class="featured-description"> 
        <div class="feat_desc"> 
         <p class="meta-info"><?php esc_html_e('Posted','henrik'); ?> <?php esc_html_e('by','henrik'); ?> <?php the_author_posts_link(); ?> <?php esc_html_e('on','henrik'); ?> <?php the_time(esc_attr(get_option('henrik_date_format'))) ?></p> 
         <h2 class="featured-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
         <p><?php truncate_post(410); ?></p> 
        </div> 
        <a href="<?php the_permalink(); ?>" class="readmore"><?php esc_html_e('Read More', 'henrik'); ?></a> 
       </div> <!-- end .description --> 
     <?php if ($responsive) { ?> 
      </li> <!-- end .slide --> 
     <?php } else { ?> 
      </div> <!-- end .slide --> 
     <?php } ?> 
     <?php $ids[] = $post->ID; $i++; endwhile; endif; wp_reset_query(); ?> 
<?php if ($responsive) { ?> 
    </ul> <!-- end .slides --> 
<?php } else { ?> 
    </div> <!-- end #slides --> 
<?php } ?> 
</div> <!-- end #featured --> 

<div id="controllers" class="clearfix"> 
    <ul> 
     <?php for ($i = 0; $i < $featured_num; $i++) { ?> 
      <li> 
       <div class="controller"> 
        <a href="#"<?php if ($i == 0) echo ' class="active"'; ?>> 
         <?php print_thumbnail($arr[$i]['thumbnail']['thumb'], $arr[$i]['thumbnail']["use_timthumb"], $arr[$i]['titletext'], $small_width, $small_height); ?> 
         <span class="overlay"></span> 
        </a> 
       </div> 
      </li> 
     <?php } ?> 
    </ul> 
    <div id="active_item"></div> 
</div> <!-- end #controllers --> 

, 코드 예제를 자세히 설명하시기 바랍니다, 감사합니다 :

여기에 슬라이더의 전체 코드입니다.

라인 39 :

<?php if (have_posts()) : while (have_posts()) : 
    global $post; 
    if (!$first_time) 
    { 
     $post_id = 6; 
     $post = get_post($post_id); 
     $first_time = 1; 
    } 
    else the_post(); 
    ?> 

솔루션 생각 아래이 하나 개의 코드로 그 라인을 대체 내가 그것을 테스트 WP 호스트를 havent,하지만 그런를 더럽 뭔가가 내 솔루션 사촌에 대한

답변

3

확실하지 않음 간단하다 :

Check for first-time loop 
    :firt loop - simply get needed post with "get_post()" function 
    :other loops - get posts from original query by "the_post()" function. 
+0

10 가지가 넘는 Q 및 A 유형의 사이트에서이 질문을했는데 이것이 유일한 해결책입니다. 피 묻은 완벽하게! 내가 지금 거기에 있었다면, 나는 너에게 키스 하겠어! 건배! –

+0

감사합니다. 흥미로운 사실 ​​- 나는 워드 프레스와 전혀 관련이 없으므로 테스트 코드를 사용하지 않고 WordPress의 문서를 검색하고 "방법"에 대해 생각해보십시오 :) – StasGrin