douzhannao5357 2014-05-13 09:46
浏览 23

从自定义帖子类型显示单个帖子

I am using the plugins and settings below. I am having some problems displaying my custom post types. I am concentrating on the printers custom post type. I have them displaying under the custom taxonomies section and have created 4 taxonomies (manufactures) so that bit is ok. (http://developmentscene.co/CKH/printers/)

The Problem
When I click on a post on the page above it displays all posts in that category. I just want it to display the post that the link you clicked on and only that post. I have tried to do this using ('posts_per_page' => 1,) But this bit of code just displays the same first post for each post I click on in the category page.

My Ideal Solution
So what I was thinking in my mind was to say only show one post with the ID of the link you clicked previously in the category. I dont know if this is the best way but I have put my code below.

<?php get_header(); ?>

<div id="wrap" class="container">

    <section id="content" class="primary" role="main">

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <?php endwhile; ?>
    <?php endif; ?>

    <?php $printers = new WP_Query(array(
        'post_type' => 'printers',
        'posts_per_page' => 1,
    )); ?>

    <?php while($printers->have_posts()) : $printers->the_post(the_ID()); ?>

    <h2 class="post-title" style="color:#333;" ><?php the_title(); ?> - <?php echo the_ID();?></h2>
    <hr >

    <p><?php the_content(); ?></p>
    <p>&nbsp;</p>
    <?php the_post_thumbnail(); ?>
    <br />


    </section>

    <section id="sidebar" class="secondary clearfix" role="complementary">


    <h3 class="widgettitle" ><b>Features and Benefits</b></h3>


    <?php $benefits = get_field( "features-and-benefits" ); 
       if($benefits){
        echo '<table cellspacing="0" cellpadding="0"><tbody>' ;
            foreach($benefits as $benefits){
                echo '<tr><td><p>' . $benefits['features'] . '</p></td></tr>' ;
            }

        echo '</tbody></table>';
       }

    ?>
    <br />

    <h3 class="widgettitle" ><b>More Information</b></h3>

    <?php $specifications = get_field( "specifications" );; 
       if($specifications){
        echo '<table cellspacing="0" cellpadding="0"><tbody>' ;
            foreach($specifications as $specifications){
                echo '<tr><td><p>' . '<a target="_blank" href="http://' . $specifications['link'] . '/">' . $specifications['details'] . '</a></p></td></tr>' ;
            }

        echo '</tbody></table>';
       }

    ?>

    </section>

    <?php endwhile; ?>



</div>

<?php get_footer(); ?>

Settings

Plugins Used:
* Custom Fields
* Custom Post Type UI

I also have permalinks set to postname.

  • 写回答

1条回答 默认 最新

  • doupo2157 2014-05-13 14:14
    关注

    You are running two loops here, and that is causing all the frustrations. I believe that you added the second loop for your specific needs, so can you can just simply delete the first loop, that is this section

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
        <?php endwhile; ?>
        <?php endif; ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行