简体   繁体   English

如何在index.php页面中显示2个类别

[英]How to display 2 categories in the index.php page

I want to display a simple front page with 2 categories, 我想显示一个包含2个类别的简单首页,

But when I enter 2 same code, the result is empty, 但是当我输入2个相同的代码时,结果为空,

But one code, the result appears 但是一个代码,结果出现

I look like: 我看起来像:

Title: chicken category 标题:鸡类

Content 内容

Title: cow category 职称:牛类

Content 内容

I tried with a simple php code: 我尝试了一个简单的php代码:

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

How the best solution? 怎么最好的解决方案?

Don't use query_posts , use WP_Query instead 不要使用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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在页面顶部赋予.php文件唯一名称,并在index.php文件上显示唯一名称 - How to give a .php file unique name at top of page, and display unique name on index.php file 如何在 php 登录成功时重定向或更改 URL 以显示 index.php 页面? - How to redirect or change the URL for display of index.php page on success of login in php? WordPress类别重定向到index.php - Wordpress categories redirecting to index.php 如何使链接“ index.php?x”在页面上显示x部分 - How to make the link 'index.php?x' display x section on a page 当我在wordpress菜单中使用类别时,在index.php上设置当前页面? - Set current page on index.php when I use categories in wordpress menu? 中心index.php页面 - Centre index.php page 如何将全部重定向到ssl和index.php,而不是ssl,但是将所有页面重定向到特定页面上的index.php - How to redirect all to ssl and to index.php but not ssl but redirect all to index.php on a specific page 如何在 front-page.php 上显示类别 - How To Display Categories on front-page.php 如何使用htaccess将root和/index.php显示为/ news? - How to use htaccess to make root and /index.php display as /news? 如何在结帐页面后将用户重定向回 index.php? - How to redirect user back to index.php after checkout page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM