2016-09-20 78 views
0
類別

顯示我的崗位我是新來的wordpress,我有一個具有提供的CATEGORY_NAME後,它有一個內容,這裏是固定鏈接:http://localhost/jcjohn/2016/09/20/what-we-offer/WordPress的我查詢後不

現在我想從我的章節頁面顯示我的文章的內容。

這裏是我的部分內部代碼:

<section id = "offer"> 
<?php  
    $args = array(
     'type' => 'post', 
     'posts_per_page' => 3, 
     'category_name' => 'offer', 
    ); 
    $offerBlog = new WP_Query($args); 

    if ($offerBlog->have_post()): 
     while ($offerBlog->have_posts()): 
      $offerBlog->the_post(); 
      get_template_part('content', get_post_format()); 
     endwhile; 
    endif; 
    wp_reset_postdata();  
?> 
</section> 
+0

變「型」到$ args變量「post_type」。 – vrajesh

+0

@vrajesh謝謝你的回答,先生。仍然沒有輸出先生。請幫忙 –

+0

嘗試:將get_template_part()函數替換爲the_content(); @jc John ..注意到您在「post_type」中添加了帖子作爲'post'.. – vrajesh

回答

0

因此,這裏是你需要做的,以顯示單頁上的帖子內容。你似乎已經錯過了have_posts所以它需要像下面

注:這裏面去index.php

<?php 
$args = array(
    'post_type' => 'post', 
    'posts_per_page' => 3, 
    'category_name' => 'offer', 
); 
$offerBlog = new WP_Query($args); 
?> 
<!-- Blog Article --> 
<section id="blog"> 
    <?php 
    if ($offerBlog->have_posts()) : 
     while ($offerBlog->have_posts()) : $offerBlog->the_post(); 

     the_content(); 

     endwhile; 
    else : ?> 
     <div class="no-content"> 
      <h3>Well... it looks like we forgot to put content here.</h3> 
     </div> 
    <?php 
    endif; 
    wp_reset_postdata(); 
    ?> 
</section> 
+0

謝謝..已顯示 –

0

您嘗試使用這個循環與您具有創建類別的cat_id

query_posts(array('cat' => '1', 'posts_per_page' => 5, 'orderby' => 'title', 'order' => 'DESC')); 

您可以嘗試更換後的代碼,如下所示。

<section id = "offer"> 
<?php  
    $args = array(
     'post_type' => 'post', 
     'cat' => '1', 
     'posts_per_page' => 5, 
     'orderby' => 'title', 
     'order' => 'DESC' 
    ); 
    $offerBlog = new WP_Query($args); 

    if ($offerBlog->have_posts()): 
     while ($offerBlog->have_posts()): 
      $offerBlog->the_post(); 
      get_template_part('content', get_post_format()); 
     endwhile; 
    endif; 
    wp_reset_postdata();  
?> 
</section> 

您錯過了循環格式。

參考:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
+0

Kuhmar.P Thank you for你的答案先生,我應該把那個先生放在哪裏?對不起,我只是一個初學者,我可以把它放在我的$ args中嗎? –

+0

只需放置'cat'=>'1','posts_per_page'=> 5,'orderby '=>'title','order'=>'DESC'' in $ args by 012 old old $ args。 –

+0

and include'post_type => post' also also in $ args .. –