2013-03-14 2 views
0

해당 카테고리 아래에 내 카테고리 및 게시물을 2 열로 표시하려고합니다.Wordpress 카테고리 목록 2 열

CSS로 해결하려고했지만 그다지 좋지 않았습니다.

<?php 
    $cat_id = get_query_var('cat'); 
    $catlist = get_categories('hide_empty=0&child_of=' . $cat_id); 

    foreach($catlist as $categories_item) { 
     echo "<div class='half'>"; 
     $cat_title = get_field('category_title' , 'category_' . $categories_item->term_id); 
     echo "<ol>"; 
     echo '<h3><a href="' . get_category_link($categories_item->term_id) . '" ' . '>' . $cat_title .'</a> </h3> '; 
     query_posts(array(
     'cat' => $categories_item->term_id, 
     'posts_per_page' => 9999, 
     'order' => 'ASC', //order ascending 
     'orderby' => 'title' //order by title 
     )); 

    if (have_posts()) : while (have_posts()) : the_post(); ?> 
    <li><a href="<?php the_permalink();?>"> 
     <?php the_title(); ?> 
     </a></li> 
    <?php endwhile; endif; ?> 
    <?php echo "</ol>"; echo "</div>"; ?> 
    <?php } ?> 

어떤 아이디어 : 여기

내 코드?

미리 감사드립니다. :)

답변

1

다음에 <?php echo "</ol>"; echo "</div>"; ?> 뒤에 2 개의 카테고리가있는 경우 카운터를 추가하십시오.

귀하의 마지막 네 줄은 다음과 같이 될 것입니다 :

<?php 
$cat_id = get_query_var('cat'); 
$catlist = get_categories('hide_empty=0&child_of=' . $cat_id); 

$counter = 0; // set counter initial value 
foreach($catlist as $categories_item) { 
    $counter++; // counter increment 
    echo "<div class='half'>"; 
    $cat_title = get_field('category_title' , 'category_' . $categories_item->term_id); 
    echo "<ol>"; 
    echo '<h3><a href="' . get_category_link($categories_item->term_id) . '" ' . '>' . $cat_title .'</a> </h3> '; 
    query_posts(array(
    'cat' => $categories_item->term_id, 
    'posts_per_page' => 9999, 
    'order' => 'ASC', //order ascending 
    'orderby' => 'title' //order by title 
    )); 

if (have_posts()) : while (have_posts()) : the_post(); ?> 
<li><a href="<?php the_permalink();?>"> 
    <?php the_title(); ?> 
    </a></li> 
<?php endwhile; endif; ?> 
<?php echo "</ol>"; echo "</div>"; ?> 

<?php 
if($counter == 2){ // check is there two columns in a row 
    echo "<div class='clear'></div>"; // this div will clear float here by css 
    $counter = 0; // now reset the counter 
} 
?> 
<?php } ?> 

지금

.clear { 
    clear: both; 
} 

확인하시기 바랍니다 CSS 파일에 CSS 코드를 다음을 추가합니다. 그것은 당신을 도울 수 있습니다. 감사.

0

내 자신의 매우 간단하지만 작업 솔루션

<div class="row-fluid"> 

      <?php 
      $counter = 0; 
      $counter2 = 0; 

      $temp = $wp_query; 
      $wp_query = null; 
      $wp_query = new WP_Query(); 
      $wp_query->query('showposts=10&cat=2'.'&paged='.$paged); 
      if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?> 

      <!-- starting the loop --> 
      <div class="span6"> 

       <p><?php the_title(); ?></p> 

       <div class="row-fluid"> 
        <div class="span5"> 
         <?php $url = wp_get_attachment_url(get_post_thumbnail_id($post->ID, 'thumbnail')); ?> 
         <p><img src="<?php echo $url; ?>" /></p> 
        </div> 
        <div class="span7"> 
         <?php the_excerpt(); ?> 
         <p><a class="btn" href="<?php the_permalink(); ?>">more &raquo;</a></p> 
        </div> 
       </div> 

      </div> 

      <?php 
      $postperpage = 10; 
      $counter++; 
      $counter2++; 
      if ($counter == 2 && $counter2 <= $postperpage-1) { 
       echo '</div><div class="row-fluid">'; 
      $counter = 0; 
      } 

      if ($counter2 == $postperpage) { 
      echo '</div> <!-- the last row -->'; 
      } 
      ?> 

      <!-- loop end --> 
      <?php endwhile; ?> 
관련 문제