0

列を div 内にラップする次のコードがあります。

<div id="blogwrapper">  
<div id="blogs">    
    <?php //enable pagination on static pages and blog pages

    $col = 1; //Let's create first column
    /*Let's add pagination to post page and static page*/
    if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
    } elseif ( get_query_var('page') ) {
    $paged = get_query_var('page');
    } else {
    $paged = 1;
    }



$args = array(
    /* Add whatever you need here - see http://codex.wordpress.org/Class_Reference/WP_Query */    
     'paged' => $paged,

);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);

if($wp_query->have_posts()):?><?php while ( $wp_query->have_posts() ) : $wp_query->the_post();?>        

<?php if ($col == 1) echo '<div class="row">';//If column 1 create first row ?>
<?php if ($col == 2) echo '<div class="row2">';//If column 2 create second row ?>

    <div <?php post_class('col'.$col); ?> id="post-<?php the_ID(); ?>">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <div class="entry"> 
                <div class="featured_img">
                <?php the_post_thumbnail();
      echo '<div class="featured_caption">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>';?>
     </div><!--/featured_img-->
        <?php  // let's enable more link on pages...
        global $more;
        $more = 0;
        ?>
            <?php the_content(); ?> 
            <div class="clear"></div>               
            <div class="custom_fields"><?php the_meta(); ?></div><br/>
            <p class="postmetadata">

            <?php _e('Filed under&#58;','override'); ?> <?php the_category(', ') ?> <?php _e('by','override'); ?> <?php  the_author(); ?><br/><?php the_tags('Tags:', ', ', '<br />'); ?>
            <?php _e('Posted on:&nbsp;','override'); ?><?php the_time('l, F jS, Y'); ?><br/>

            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
        </div>
    </div>

    <?php /*Enable Two Column Layout*/
        if($col==1) {
        $col=2;
        echo "</div>";
        }
        else if($col==2)  {
        $col=1;
         echo "</div>";
        }

    endwhile; ?>
    <div class="clear"></div>
    <div class="navigation">

    <?php
    global $wp_query;
    $big = 999999999; // need an unlikely integer

    echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, $paged ),
    'total' => $wp_query->max_num_pages
    ) );
    ?>
</div>
<?php endif; ?> 
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>



</div><!--/blogs--> 
</div><!--/blogswrapper-->  

しかし、ここに問題があります:処理中の空の div (div class="row" および div class="row2")のを取得しています (たとえば、バックエンド内の読み取り設定に応じて、私の読み取り設定がブログページの表示である場合) 7 件の投稿) 出力は次のようになります: http://www.vasinternetposao.com/testall/wrap_problem.png . しかし、ブログページに 2 つの投稿を表示するように設定すると、 2 つの空の div のみが表示されます。http://www.vasinternetposao.com/testall/wrap2.pngでは、の divをすべて使わずに列を適切にラップする方法を知っている人はいますか? THX!!



4

2 に答える 2

0

私は今とてもばかげているように感じます...私は<?php if ($col == 1) echo '<div class="row">';//If column 1 create first row ?>ループの下に置くだけで、うまくいきました! したがって、私の作業コードは次のようになります。

    <?php /* Template name: Two Columns*/   
    ?>  

 <?php get_header(); ?>

 <?php get_sidebar(); ?>

 <?php get_sidebar('secondary'); ?>

<div id="blogwrapper">  
<div id="blogs">    

    <?php //enable pagination on static pages and blog pages

    $col = 1; //Let's create first column
    /*Let's add pagination to post page and static page*/
    if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
    } elseif ( get_query_var('page') ) {
    $paged = get_query_var('page');
    } else {
    $paged = 1;
    }



$args = array(
    /* Add whatever you need here - see http://codex.wordpress.org/Class_Reference/WP_Query */    
     'paged' => $paged,

);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);

if($wp_query->have_posts()):?><?php while ( $wp_query->have_posts() ) : $wp_query->the_post();?>        



    <div <?php post_class('col'.$col); ?> id="post-<?php the_ID(); ?>">
            <!--NOTICE THAT THIS CODE IS NOW BELOW!!!-->

    <?php if ($col == 1) echo '<div class="row">';//If column 1 create first row ?>
    <?php if ($col == 2) echo '<div class="row2">';//If column 2 create second row ?>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <div class="entry"> 
                <div class="featured_img">
                <?php the_post_thumbnail();
      echo '<div class="featured_caption">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>';?>
     </div><!--/featured_img-->
        <?php  // let's enable more link on pages...
        global $more;
        $more = 0;
        ?>
            <?php the_content(); ?> 
            <div class="clear"></div>               
            <div class="custom_fields"><?php the_meta(); ?></div><br/>
            <p class="postmetadata">

            <?php _e('Filed under&#58;','override'); ?> <?php the_category(', ') ?> <?php _e('by','override'); ?> <?php  the_author(); ?><br/><?php the_tags('Tags:', ', ', '<br />'); ?>
            <?php _e('Posted on:&nbsp;','override'); ?><?php the_time('l, F jS, Y'); ?><br/>

            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
        </div>
    </div>

    <?php /*Enable Two Column Layout*/
        if($col==1) {
        $col=2;
        echo "</div>";
        }
        else if($col==2)  {
        $col=1;
         echo "</div>";
        }

    endwhile; ?>
    <div class="clear"></div>
    <div class="navigation">

    <?php
    global $wp_query;
    $big = 999999999; // need an unlikely integer

    echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, $paged ),
    'total' => $wp_query->max_num_pages
    ) );
    ?>
</div>
<?php endif; ?> 
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>



</div><!--/blogs--> 
</div><!--/blogswrapper-->  
于 2013-05-22T18:20:49.620 に答える