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 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100