2012-01-17 49 views
0

我已經開始啃我自己的wordpress模板,第一步我用HTML製作了草圖。這是這樣的。用於顯示內容的PHP循環

Sketch

我在想這件事,黑色矩形是「後的圖像」,我想4一行。我應該用for循環來解決,while循環(我猜)。 在我看來,這應該是這樣的(它的循環,從二11主題)

<?php 
get_header(); ?> 

     <div id="primary"> 
      <div id="content" role="main"> 

       <?php while (have_posts()) : the_post(); ?> 
        <?php for(i=0;i<8;i++)?> 
        {<?php get_template_part('content', 'page'); ?>} 
        <?php comments_template('', true); ?> 

       <?php endwhile; // end of the loop. ?> 

      </div> 
     </div> 
<?php get_footer(); ?> 

但我有問題,我應該如何與定位解決問題。我想這應該是一個職位的職位。下面我給你我的代碼。請幫忙。

我的html代碼:

<div class="postbar"> 
    <div class="post1"> 
     <a href="index.html"> 
     <div id="postOver"></div> 
     </a> 
     <div id="postText">text</div> 
    </div> 
    <div class="post2"> 
     <a href="index.html"> 
     <div id="postOver"></div> 
     </a> 
     <div id="postText">text</div> 
    </div> 
    <div class="post3"> 
     <a href="index.html"> 
     <div id="postOver"></div> 
     </a> 
     <div id="postText">text</div> 
    </div> 
    <div class="post4"> 
     <a href="index.html"> 
     <div id="postOver"></div> 
     </a> 
     <div id="postText">text</div> 
    </div> 
</div> 
<div class="postbar"> 
    <div class="post1"> 
     <a href="index.html"> 
     <div id="postOver"></div> 
     </a> 
     <div id="postText">text</div> 
    </div> 
    <div class="post2"> 
     <a href="index.html"> 
     <div id="postOver"></div> 
     </a> 
     <div id="postText">text</div> 
    </div> 
    <div class="post3"> 
     <a href="index.html"> 
     <div id="postOver"></div> 
     </a> 
     <div id="postText">text</div> 
    </div> 
    <div class="post4"> 
     <a href="index.html"> 
     <div id="postOver"></div> 
     </a> 
     <div id="postText">text</div> 
    </div> 
</div> 

我的CSS代碼:

div.postbar{ 
     position:relative; left:255px; 
     height:222px; 
     } 
    div.post1 { 
     margin-top:17px; 
     position:relative; 
     margin-left:1%; 
     padding-left:3px; 
     padding-right:3px; 
     width:222px; 
     height:222px; 
     } 
    div.post2 { 
     position:absolute; top:-1px; left:260px; 
     margin-left:1%; 
     width:222px; 
     height:222px; 
     } 
    div.post3 { 
     position:relative; top:-222px; left:520px; 
     margin-left:1%; 
     padding-left:3px; 
     padding-right:3px; 
     width:222px; 
     height:222px; 
     } 
    div.post4 { 
     position:relative; top:-444px; left:780px; 
     margin-left:1%; 
     padding-left:3px; 
     padding-right:3px; 
     width:222px; 
     height:222px; 
     } 
    div.postNext { 

     position:absolute; left:250px; top:-1px; 
     margin-left:1%; 
     padding-left:3px; 
     padding-right:3px; 
     width:222px; 
     height:222px; 

     } 

    #postOver{ 
     width:222px; 
     height:222px; 
     background-image:url(img/arch.jpg); 
     box-shadow:0px 0px 3px #000000; 
     -webkit-transition:width 1s; 
     } 
    *:hover > #postOver{ 
     width: 0; 
    } 
    #postText{ 
     position:relative; top:-222px; 
     font-size:12px; 
     width:222px; 
     height:222px; 
     box-shadow:0px 0px 3px #000000; 
     color:black; 
     text-align:center; 
     z-index:-1; 
     } 
+0

你會希望做一個自定義模板,並利用它來進行顯示。 http://codex.wordpress.org/Pages#Examples_of_Pages_and_Templates – MetalFrog 2012-01-17 19:21:59

+0

它看起來像你正在使用CMS ..沒有看到建立內容的實際頁面,它將很難調整它。你在使用joomla/Wordpress/etc嗎?一些模塊可能變得非常多毛。 – Silvertiger 2012-01-17 19:22:53

+0

@Silvertiger我正在使用wordpress – 2012-01-17 19:24:05

回答

0

像Mr.TAMER說,將是更好的搜索在WordPress Exchange答案。

這裏是代碼,可能是你的問題可能的解決方案:

<style type="text/css"> 
    .post { float:left; display:block; width:222px; height:222px; margin: 0 3px; } 
    .post.first { margin-left:0px; } 
    .post.last { margin-right:0px; } 

    /* Clear fix from http://css-tricks.com/snippets/css/clear-fix/ */ 
    .clearfix:after { visibility: hidden;display: block;font-size: 0;content: " ";clear: both;height: 0; } 
    * html .clearfix { zoom: 1; } /* IE6 */ 
    *:first-child+html .clearfix { zoom: 1; } /* IE7 */ 
</style> 

<?php 
    $args = array(//Query variables take a look at http://codex.wordpress.org/Class_Reference/WP_Query 

    ); 
    $query = new WP_Query($args); // Doing the Query 

    if($query->have_posts()) { // Checking if there is any posts with the arguments above 

     while($query->have_posts()) { // Looping throught the selected posts 
      $query->the_post(); // Selecting the next as the actual Post 
      ?> 
      <div class="post<?php echo ($current_post == 0 ? " first" : ($current_post == $post_count ? " last" : "")); ?>"> 
       <a href="index.html"> 
        <div id="postOver"></div> 
       </a> 
       <div id="postText">text</div> 
      </div> 
      <?php 
      if($current_post == $post_count) 
       echo "<div class=\"clearfix\"></div>"; 
     } 
    } else { // If there isn't any posts with the Arguments set above 


    } 
    wp_reset_postdata(); // Reseting the Post data so you can re-use the loop 
+0

我去Wordpress交流,他們告訴我,我應該去這裏。洙 – 2012-01-17 21:22:43