douyinmian8151 2015-04-09 10:59
浏览 43
已采纳

too long

I'm using a custom post query to pull some data from Wordpress into a slider. I then want to get the post content from the actual page that the slider is on but the post data doesn't seem to reset and pull through the original data.

If I put my second code block in <div class='main'> above the custom slider post code then the data is pulled through.

How can I reset my post data elegantly?

<div class="banner">

    <?php
        //PULL THROUGH THE DATA
        $type = 'slider';
        $args = array(
          'post_type' => $type,
          'post_status' => 'publish',
          'order' => 'ASC',
          'posts_per_page' => -1
        );
        $posts = get_posts($args);
    ?>

    <ul class="slider">
        <?php foreach ($posts as $post) : setup_postdata($post); ?>

            <?php
                $thumb_id = get_post_thumbnail_id();
                $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full', true);
                $thumb_url = $thumb_url_array[0];
            ?>

            <li><img src="<?php echo $thumb_url;?>" title="<?php echo get_the_title(); ?>" /></li>

        <?php endforeach; wp_reset_postdata(); ?>
    </ul>

</div>


<div id="main">

    <div class="container">

        <div class="row">

            <?php if(have_posts()) : ?>

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

                <div class="col-sm-8">
                    <?php the_content(); ?>
                </div>

            <?php endwhile; ?>

            <?php endif; ?> 

            <div class="col-sm-4">
                <h3>Latest tweets</h3>
            </div>

        </div>

    </div>

</div>

I hope that makes sense. Please let me know if my requirements are unclear.

  • 写回答

1条回答 默认 最新

  • dou4064 2015-04-09 11:15
    关注
    <?php
    get_post( $id, $output, $filter );
    $post_7 = get_post(7); 
    $title = $post_7->post_title;
    ?> 
    

    https://codex.wordpress.org/Function_Reference/get_post

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?