0
<?php if (in_category('3')) {
        $args = array(
        'cat' => 'Japan',
        'orderby' => 'meta_value_num', 
        'meta_key' => 'japan_id',
        'order' => 'ASC',
        );
        $the_query = new WP_Query( $args );

        } elseif (in_category('5')) {
        $args = array(
        'cat' => 'Borneo',
        'orderby' => 'meta_value_num', 
        'meta_key' => 'borneo_id',
        'order' => 'ASC',
        );
        $the_query = new WP_Query( $args );}?>

        <?php while ( $the_query->have_posts() ) : $the_query->the_post();?> 
        <?php $status = get_post_meta($post->ID, 'status', true); ?><?php $finishdate = get_post_meta($post->ID, 'finishdate', true); ?>
        <a href="<?php the_permalink(); ?> " rel="favourite" title="<?php the_title(); ?>"><?php the_post_thumbnail('featured-thumbnail'); ?></a>
        <?php endwhile; ?>
        <?php
       // Reset Post Data
       wp_reset_postdata();?>

大家好,我正在尝试做一个 if 和 elseif 来检查:

  • 如果这篇文章属于第 3 类
  • 获取此帖子的信息(类别名称,按此 meta_key 的元值编号按 ASC 顺序排列
  • 否则,如果这篇文章属于第 5 类
  • 获取此帖子的信息...按 ASC 顺序

但是,我不断收到错误消息“致命错误:在...在线的非对象上调用成员函数 have_posts()....”我想显示来自的所有帖子的所有精选缩略图与 Single Post 相同的类别。

单个帖子的示例: http ://ethanlimphotos.com/2012/04/19/orangutan-grabs-legs 特色缩略图滚动应该像这样显示http://ethanlimphotos.com 我想要索引页面上的特色缩略图滚动也可以在单页上工作。请帮忙,谢谢!:D

4

1 回答 1

0

我真的不明白为什么几乎每个人都在想要进行自定义循环时创建一个新对象:) 这是因为这是您看到示例的方式,还是您有不同的原因(我真的很好奇 :)) .

无论如何,当我需要自定义循环时,我的方式是调用query_posts(),使用正常have_posts()the_post()然后使用 .reset 重置查询变量wp_reset_query()。因此,当您使用该方法时,您的代码将如下所示:

<?php if (in_category('3')) {
    $args = array(
    'cat' => 'Japan',
    'orderby' => 'meta_value_num', 
    'meta_key' => 'japan_id',
    'order' => 'ASC',
    );
    query_posts( $args );
} elseif ( in_category( '5' ) ) {
    $args = array(
        'cat' => 'Borneo',
        'orderby' => 'meta_value_num', 
        'meta_key' => 'borneo_id',
        'order' => 'ASC',
    );
    query_posts( $args );
}?>

<?php while ( have_posts() ) : the_post(); ?> 
    <?php $status = get_post_meta($post->ID, 'status', true); ?><?php $finishdate = get_post_meta($post->ID, 'finishdate', true); ?>
    <a href="<?php the_permalink(); ?> " rel="favourite" title="<?php the_title(); ?>"><?php the_post_thumbnail('featured-thumbnail'); ?></a>
<?php endwhile; ?>
<?php
// Reset the query data
wp_reset_query();?>
于 2012-11-25T16:32:13.043 回答