2014-12-09 4 views
0

categoriesid 9에이 템플릿을 반복하는 데 도움이 필요합니다. 이것은 지금까지 내가 한 것입니다 :Wordpress Looping 카테고리 ID

$columns  = false; 
$rows  = false; 
$image_sizes = array(); 

if (have_posts()) : 

    if (is_page()) { 

     $grid_portfolio = new GridPortfolio(get_the_ID()); 
    // Sets: $orientation, $aspect_ratio, $grid_size, $image_sizes, $columns, $rows 
     extract($grid_portfolio->get_options()); 

    } else { 

     $default_grid_portfolio = it_find_page_by_template('template-portfolio-grid.php', array('post_status' => 'publish')); 

     if ($default_grid_portfolio) { 
      $grid_portfolio = new GridPortfolio($default_grid_portfolio[0]->ID); 
      extract($grid_portfolio->get_options()); 
     } 

     /** 
     * We are on a Project Type page, 
     * thus we need to check if there is any overriden options. 
     * 
     * Sets: $orientation, $aspect_ratio, $grid_size, $image_sizes, $columns, $rows 
     */ 
     extract(fluxus_project_type_grid_options(get_queried_object()->term_id)); 

    } 
    if (! is_numeric($columns)) { 
     $columns = 4; 
    } 

    if (! is_numeric($rows)) { 
     $rows = 3; 
    } 

    $max_size = $orientation == 'horizontal' ? $rows : $columns; 

    fluxus_add_html_class('layout-portfolio-grid layout-portfolio-grid-' . $orientation); 

    if ($orientation != 'vertical') { 
     fluxus_add_html_class('horizontal-page'); 
    } 
    get_header(); 

    fluxus_query_portfolio(array(
     'fluxus-project-type' => get_query_var('fluxus-project-type') 
    )); 

    ?> 
    <div id="main" class="site"> 

     <div class="portfolio-grid" data-aspect-ratio="<?php esc_attr_e($aspect_ratio); ?>" data-orientation="<?php esc_attr_e($orientation); ?>" data-columns="<?php echo $columns; ?>" data-rows="<?php echo $rows; ?>"><?php 

      while (have_posts()) : 

       the_post(); 
    $project = new PortfolioProject(get_the_ID()); 
       $featured = $project->get_featured_media(); 

       if (! $featured) continue; // We have no media on this project, nothing to show. 

       $thumbnail = FLUXUS_IMAGES_URI . '/no-portfolio-thumbnail.png'; 
       $thumbnail_2x = ''; 

       $thumbnail_data = $featured->get_thumbnail('fluxus-thumbnail'); 
       $thumbnail_data_2x = $featured->get_thumbnail('fluxus-thumbnail-2x', 'fluxus-thumbnail'); 

       if ($thumbnail_data) { 
        $thumbnail = $thumbnail_data['src']; 
       } 

       if ($thumbnail_data_2x) { 
        $thumbnail_2x = $thumbnail_data_2x['src']; 
        if ($thumbnail_2x == $thumbnail) { 
         $thumbnail_2x = ''; 
        } 
       } 
    if (isset($image_sizes[get_the_ID()])) { 
        $size = $image_sizes[get_the_ID()]; 
        $size = $size > $max_size ? $max_size : $size; 
       } else { 
        $size = 1; 
       } ?> 
       <article class="grid-project size-<?php echo $size; ?>" data-size="<?php echo $size; ?>" data-id="<?php echo esc_attr(get_the_ID()); ?>"> 
        <a href="<?php the_permalink(); ?>" class="preview" style="background-image: url(<?php echo esc_url($thumbnail); ?>);" data-hd-image="<?php echo esc_url($thumbnail_2x); ?>"> 
         <span class="hover-box"> 
          <span class="inner"><?php 
           if ($project->meta_subtitle) : ?> 
            <i><?php echo $project->meta_subtitle; ?></i><?php 
           endif; ?> 
           <b><?php the_title(); ?></b> 
           <?php if (post_password_required()) : ?> 
            <span class="password-required"> 
             <?php _e('Password required', 'fluxus'); ?> 
            </span> 
           <?php endif; ?> 
          </span> 
         </span> 
         <?php 
         /** 
         * Add <img /> tag, so that they can be found 
         * by search engines and social sharing widgets. 
         */ ?> 
         <img class="hide" src="<?php echo esc_url(! empty($thumbnail_2x) ? $thumbnail_2x : $thumbnail); ?>" alt="<?php esc_attr_e(get_the_title()); ?>" /> 
        </a> 
       </article><?php 
      endwhile; ?> 
     </div> 
    </div> 
<?php 
else: 
    get_header(); 
endif; 
wp_reset_query(); 
get_footer(); 
+0

을 권하고 싶습니다? 코드가 출력되기를 기대하고있는 것은 무엇입니까? – iblamefish

+0

안녕하세요 Mr.Programmer 그 템플릿 카테고리 ID 9 루프해야합니다. – encabswork

+0

카테고리를 루프에 삽입하는 방법은 무엇입니까? – encabswork

답변

0

템플릿에서 언급 했으므로, review the WP template hierarchy입니다. 이렇게하면 특정 범주를 볼 때와 같이 특정 상황에서 사용할 템플리트를 지정할 수 있습니다. 그것은 당신의 템플릿 category-9.php 이름을 바꾼만큼 간단합니다 : 당신이 (홈 페이지에서 eaxmple에 대한) 다른 템플릿을 categpry 게시물 표시에 대해 얘기하고 경우 example.com/blog/?cat=9

를 방문했을 때이 템플릿은 다음 사용됩니다, 당신은 필요 실제로 반복 할 수 있기 전에 일부 게시물을 쿼리 할 수 ​​있습니다. 당신은 당신의 오프닝 if (have_posts()) 전에 이것을해야합니다. 수신 한 게시물을 변경하는 쿼리에 대해 다른 매개 변수를 설정할 수 있습니다. One of these available parameters is cat을 사용하면 게시물을 가져올 카테고리를 지정할 수 있습니다. 당신은 너무처럼 사용하십시오 :

$args = (
    'cat' => 9 
); 
$query = new WP_Query($args); 
if ($query->have_posts()) { 
    while ($query->have_posts()) {) { 
    // The rest of the code here 

내가 강력하게 당신에게 당신이 무엇을 잘못 무엇 read up on how WP_Query works

+0

입니다. 코드를 넣을 곳은 어디입니까? ? 여기 에서 경우 (have_posts()) : 경우 (is_page()) { $ grid_portfolio = 새로운 GridPortfolio (get_the_ID()); 또는 여기 while (have_posts()) : the_post(); $ project = new PortfolioProject (get_the_ID()); $ featured = $ project-> get_featured_media(); if (! $ featured) continue; //이 프로젝트에는 언론도없고 보여줄 것도 없습니다. $ 미리보기 = FLUXUS_IMAGES_URI. '/no-portfolio-thumbnail.png'; $ thumbnail_2x = ''; – encabswork

+0

위의 코드를 사용하여 루프 카테고리를 만들 수 있습니까? 작성 : ( – encabswork