2017-05-17 21 views
0

我想用2個類別,以顯示一個簡單的頭版,如何顯示2個類別的index.php頁面

但是,當我進入2相同的代碼,結果是空的,

但一個代碼,結果出現

我的樣子:

標題:雞類

內容

標題:牛類

內容

我用一個簡單的PHP代碼的嘗試:

<h2 class="home1">10 Best Chicken</h2> \t 
 
<div class="1"><?php query_posts('cat=9' . '&showposts=3'.'&paged='.$paged); ?></div> 
 

 
<h2 class="home1">10 Best Cow</h2> \t 
 
<div class="1"><?php query_posts('cat=10' . '&showposts=3'.'&paged='.$paged); ?></div>

如何最好的解決辦法?

回答

1

不要使用query_posts,使用WP_Query代替

<?php get_header(); ?> 
<?php if((is_home())&& ($paged < 1)) { ?> 
<?php get_template_part('home-featured'); ?> 
<?php } ?> 
<div class="wisata-konten"> 
<div class="container"> 
<div class="row">  
<div class="col-md-12"> 
<?php if((is_home())&& ($paged > 1)) { ?> 
<h1><?php bloginfo('name'); ?> - <?php if (get_query_var('paged')) { echo 'Halaman '. get_query_var('paged'); } ?></h1> 
<?php } ?> 

<div class="row"><div class="boxer2"> 
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
<div class="col-md-4"><?php get_template_part('thumb'); ?></div> 
<?php endwhile; ?></div></div> 

<?php fastestwp_pagenavi(); ?> 
<?php else : ?> 
<h2>Not Found</h2>Sorry, but you are looking for something that isn't here. 
<?php endif; ?> 
<h2 class="home1">Lombok Open Trip</h2> 
<?php $args = array('cat' => 9 , 'posts_per_page' => 3 , 'paged' => $paged); 


$the_query = new WP_Query($args); 

// The Loop 
if ($the_query->have_posts()) { 
    echo '<ul>'; 
    while ($the_query->have_posts()) { 
     $the_query->the_post(); 
     echo '<li>' . get_the_title() . '</li>'; 
    } 
    echo '</ul>'; 
    /* Restore original Post Data */ 
    wp_reset_postdata(); 
} else { 
    // no posts found 
} 
?><h2 class="home1">Lombok Promo</h2><?php 
$args2 = array('cat' => 10 , 'posts_per_page' => 3 , 'paged' => $paged); 

$the_query2 = new WP_Query($args2); 

// The Loop 
if ($the_query2->have_posts()) { 
    echo '<ul>'; 
    while ($the_query2->have_posts()) { 
     $the_query2->the_post(); 
     echo '<li>' . get_the_title() . '</li>'; 
    } 
    echo '</ul>'; 
    /* Restore original Post Data */ 
    wp_reset_postdata(); 
} else { 
    // no posts found 
} ?> 
<div class="wisata-testimoni"> 
<div class="container"> 
<div class="row"> 
<div class="col-md-12">      
<div id="testimoni" class="carousel slide"> 
<div class="carousel-inner"> 
<?php fastestwp_comments(); ?> 
</div> 
</div> 
<div class="tombol"><a class= "medium beli blue pull-right" href="<?php echo home_url() ; ?>/testimoni" >Lihat Semua Testimoni <span class="glyphicon glyphicon-thumbs-up"></span></a></div> 
</div> 
</div> 
</div> 
</div> 
+0

我在哪裏申請這個代碼? 無論是在function.php還是直接粘貼index.php –

+0

你可以通過2種方式做到這一點,1st - 直接放在index.php中 2nd - 在functions.php中爲此寫一個shortcode並在索引中調用shortcode。 php –

+0

我應該在哪裏放置代碼?請在評論中看到我的完整index.php代碼 –

相關問題