2012-10-23 55 views
0

我對wordpress很新穎,所以請耐心等待。我有一個網站正在運行,允許我動態地添加內容,唯一的問題是每個帖子的樣式。我正在尋找包裝在一個div的帖子,所以圖像將被包裹在一個div和文本帖子將被包裹在另一個,如果這是有道理的?
下面是一些代碼,我一直在使用:
Wordpress,在div中包裹帖子

<?php if (in_category('photos')) { ?> 
      <div id="testing"> 
<?php } else { ?> 
      <div id="test-2"> 
<?php } ?> 

與此唯一的問題是,它包裹在一個給定類別的所有訊息,並且不把關閉「</DIV>」後的內容,如果這是有道理的?

+2

@Svetlio'寫你的代碼'? – user1374796

回答

0

那麼,你沒有得到任何關閉</div> s的唯一原因是你沒有把它放在你的php的任何地方。

這應該工作:

<?php while(have_posts()) : the_post() 
    if(in_category('photos') { ?> 
    <div id="testing"> 
     // All your post content and whatnot 
     <?php the_content(); ?> 
    </div> 
    <?php } else { ?> 
    <div id="test-2"> 
     // All your post content 
     <?php the_content(); ?> 
    </div> 
    <?php } 
    endwhile; ?> 

如果你不寫在你的主題文件的完整的標記,你不可能指望Wordpress或PHP,自動關閉你的HTML標籤。

0

「如果有道理」不,它沒有任何意義,因爲默認情況下,Wordpress會爲每個類別添加一個CSS類,併爲周圍的div添加標籤。如果您的主題不是這種情況,請使用功能post_class()將CSS類添加到您的div

有關使用示例,請參閱the post_class()-documentation