Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在wordpress主页上显示多个类别_Php_Wordpress - Fatal编程技术网

Php 如何在wordpress主页上显示多个类别

Php 如何在wordpress主页上显示多个类别,php,wordpress,Php,Wordpress,(wordpress) 尝试在主页上显示两个单独的类别,其中“Garmin Quatix GPS手表”和“West Marine帆船手套3/4手指”现在显示(两者都来自同一类别) 我假设下面的代码是我需要编辑的地方(从index.php),但也许我离编辑太远了 <div id="content" class="columns col10"> <?php $cat_headline=get_option('colabs_cat_headline'); if($ca

(wordpress)

尝试在主页上显示两个单独的类别,其中“Garmin Quatix GPS手表”和“West Marine帆船手套3/4手指”现在显示(两者都来自同一类别)

我假设下面的代码是我需要编辑的地方(从index.php),但也许我离编辑太远了

<div id="content" class="columns col10">
<?php
    $cat_headline=get_option('colabs_cat_headline');
    if($cat_headline=='')$cat_headline=1;
    $cat_featured=get_option('colabs_cat_featured');
    if($cat_featured=='')$cat_featured=1;
    query_posts('showposts=2&cat='.$cat_headline);
    $i=1;
    if ( have_posts() ) :
    ?>
<div class="headline columns col10">
    <?php while ( have_posts() ) : the_post(); ?>
    <div class="featured column <?php if ($i==1){?>col6<?php }else{ ?>col4<?php }?>">
        <?php 
        if ($i==1){$image_headline_width=474;$image_headline_height=318;}else{$image_headline_width=306;$image_headline_height=215;}
        colabs_image('width='.$image_headline_width.'&height='.$image_headline_height.'&play=true'); 
        $i++;
        ?>
        <h3 class="headline-title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
        <p><?php excerpt();?></p>
        <a href="<?php the_permalink();?>" class="more-link"><?php _e('Continue Reading','colabsthemes');?> &rarr;</a>
    </div><!-- .featured1 -->
    <?php endwhile; ?>

</div><!-- .headline -->
<?php endif; ?>

<?php colabs_latest_post(5,'col10');?><!-- .recent-entry -->



</div><!-- #content -->


快速回答,但是。。。试试这个: 修改
query\u posts()
调用以从两个类别收集帖子,假设您知道或可以找到它们的id
query\u posts()
是数据库检索的实际操作

query_posts( array( 'category__and' => array(ID_OF_FIRST_CATEGORY, ID_OF_SECOND_CATEGORY) );

您的查询只传递一个类别。因此,您的查询只能包含一个类别中的帖子。您可能需要来自$cat_headline$cat_featured类别的帖子

因此,您应该修改
query_posts('showposts=2&cat='。$cat_headline)带有
query_posts('posts_per_page'=>2,'category_'=>array($cat_headline,$cat_featured))

您的代码如下所示:

$cat_headline=get_option('colabs_cat_headline');
if($cat_headline=='')$cat_headline=1;

$cat_featured=get_option('colabs_cat_featured');
if($cat_featured=='')$cat_featured=1;

query_posts( array('posts_per_page' => 2, 'category__and' => array($cat_headline, $cat_featured)) );
检查完整的文档,它可以帮助您更多


谢谢。

所以你说要替换这行查询帖子('showposts=2&cat='。$cat\u headline);使用query_posts(array('category_uand'=>array(1225))?这样做会导致一个错误,我在页面加载时只会看到一个白色屏幕。我是否没有正确输入类别ID?谢谢如果类别ID是这样的,那么是的。此时,我会打开错误显示(或检查错误日志)看看错误到底是什么。根据WP Codex,这应该是正确的代码。请检查我的答案。也许它可以帮助你。在这里迷路了,很抱歉我的无知。我如何/在哪里更改我想要显示的类别?谢谢:)我想我刚刚换掉了$cat_headline,$cat_以225,26为例。但是这会使网站崩溃:(对不起,我错过了
query\u post
中的
数组。你现在可以试试了。