WP Single.php If和elseif语句执行

时间:2012-11-25 15:50:00

标签: wordpress

<?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类
  • 获取此信息的信息(类别名称,按ASC顺序中此meta_key的元数值排序
  • 如果这个帖子属于第5类
  • 以ASC顺序获取此帖子的信息

然而,我不断收到错误“致命错误:在...上的非对象上调用成员函数have_posts()....”我想显示所有帖子的所有精选缩略图与Single Post属于同一类别。

单一帖子示例:http://ethanlimphotos.com/2012/04/19/orangutan-grabs-legs 功能缩略图滚动应显示为http://ethanlimphotos.com 我希望索引页面上的精选缩略图滚动也可以在单页面上工作。 请帮帮忙,谢谢! :d

1 个答案:

答案 0 :(得分:0)

我真的不明白为什么几乎每个人都想在自定义循环中创建一个新对象:)这是因为这是你看到一个例子的方式,或者你有不同的理由(我真的很好奇:))。

无论如何,当我需要自定义循环时,我的方法就是调用query_posts(),使用普通have_posts()the_post(),然后使用{{1}重置查询变量}。这就是使用该方法时代码的样子:

wp_reset_query()
相关问题