2014-08-29 113 views
1

如何查看我的代碼以顯示主主頁的類別預覽? 現在,它是內容下的WordPresspress帖子

<?php $posts = get_posts ("category=2&orderby=date&numberposts=3"); ?> 
<?php if ($posts) : ?> 
<?php foreach ($posts as $post) : setup_postdata ($post); ?> 
<div> 
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> 
</div> 
<?php endforeach; ?> 
<?php endif; ?> 

低於這個

<?php if(have_posts()): ?> 
<?php while(have_posts()): the_post(); ?> 
    <div class="pageContainer"><?php the_content(); ?></div> 
<?php endwhile; ?> 
<?php wp_reset_postdata(); ?> 
<?php else: ?><div>Sorry, posts are not found.</div> 
<?php endif; ?> 

這導致忽略第二部分...

對不起,我的英語水平。

+0

你對'預覽fo類別'有什麼意思? – 2014-08-29 19:31:52

+0

我的第一部分代碼 - 爲了通過id = 2顯示catrgory的標題。在頁面上,在這部分代碼下面,我嘗試顯示頁面使用第二部分的內容,第一部分導致忽略第二部分,並顯示帖子 – soovorow 2014-08-29 19:45:57

+0

該代碼將首先列出所有標題,然後一次標題已列出,它將開始打印頁面內容。那是你想要展示的嗎? – Howli 2014-08-29 20:14:54

回答

1
<?php 
     // Category posts 
     $posts = get_posts("category=2&orderby=date&numberposts=3"); 
     if ($posts){ 
      foreach ($posts as $article){ 
      echo '<div><a href="'.get_permalink($article->ID) ?>" rel="bookmark">'. 
        $article->post_title.'</a></div>'; 
      } 
     } 

     // Current page content 
     if (have_posts()) : 
     while (have_posts()) : the_post(); ?> 
      <div class="pageContainer"> 
       <?php the_content(); ?> 
      </div> 
     <?php endwhile; 
     else: 
      echo '<div>Sorry, posts are not found.</div>'; 
     endif; 
     ?> 
相關問題