Php 使用WordPress自定义帖子类型

Php 使用WordPress自定义帖子类型,php,jquery,wordpress,twitter-bootstrap,Php,Jquery,Wordpress,Twitter Bootstrap,我正在尝试使用Wordpress和引导carousal。我创建了一个名为images的自定义帖子类型,并将其链接到我想要的帖子。然后,我将图像上传到每个帖子,当我在数组中循环时,它会在旋转木马中输出我所有的图像。这意味着要通过我的自定义图像字段中的每个图像,并在旋转木马中对它们进行回音 它还输出无重复中心;“>在我的html页面上显示为纯文本。我不知道为什么 <?php get_header(); ?> <?php global $wp_query; $posti

我正在尝试使用Wordpress和引导carousal。我创建了一个名为images的自定义帖子类型,并将其链接到我想要的帖子。然后,我将图像上传到每个帖子,当我在数组中循环时,它会在旋转木马中输出我所有的图像。这意味着要通过我的自定义图像字段中的每个图像,并在旋转木马中对它们进行回音

它还输出
无重复中心;“>
在我的html页面上显示为纯文本。我不知道为什么

  <?php 
get_header(); 
?>

<?php 

global $wp_query;
$postid = $wp_query->post->ID;
wp_reset_query();

$images = get_post_meta($postid, 'images', false);


?>


<div class="row">
    <div class="col-md-3">
        <div id="page_title">Case Studies</div>
    </div>
    <div class="col-md-9">
        <div id="page_excerpt">
            <div class="vertical_align_centre">
                <?php the_excerpt();?>
            </div>
        </div>
    </div>
</div>

<!-- Content -->


<div class="row">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; endif; ?>

<div class="col-md-3">

    <?php the_post_thumbnail('casestudy img-responsive');?>
</div>

     <div class="carousel-row hidden-xs">
            <div class="col-md-9">
                <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
                    <!-- Indicators -->
                    <ol class="carousel-indicators">
                        <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
                        <li data-target="#carousel-example-generic" data-slide-to="1"></li>
                        <li data-target="#carousel-example-generic" data-slide-to="2"></li>
                    </ol>

                    <!-- Wrapper for slides -->
                    <div class="carousel-inner"> 
                        <?php $i=0; foreach ($images as $image) { ?> 
                        <div class="item <?php if ($i == 0) { echo 'active'; } ?>" style="background-size:cover; background:url('<?php echo $image; ?>') no-repeat center;">
                            <div class="carousel-caption">
                                <h4><?php echo $imageURL->post_excerpt;?></h4>
                            </div>
                        </div>
                        <?php $i++; } ?>
                    </div>
                    <!-- Controls -->
                    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
                        <span class="glyphicon glyphicon-chevron-left"></span>
                    </a>
                    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
                        <span class="glyphicon glyphicon-chevron-right"></span>
                    </a>
                </div>
              </div>
            </div>

案例研究

  • 从查询中,您似乎获得了阵列中所有可用的帖子

    您可以在顶部修复此问题:

    'numberposts' = 10, //or however many you want
    
    或者在事件发生后切掉数组:

    $attachments = array_slice($attachments ,0 ,10);
    


    我就是这样理解你的问题的

    您创建了一个名为images的自定义post类型,并将post添加到该post类型中。这些post包含一个图像(我假设您正在使用post缩略图)。因此,您需要将这些图像用作引导转盘

    如果我是对的,这是你的答案。请注意,这段代码没有经过测试。所以在尝试之前,请备份你的代码

    <?php get_header(); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="row">
    <div class="col-md-3">
        <div id="page_title">Case Studies</div>
    </div>
    <div class="col-md-9">
        <div id="page_excerpt">
            <div class="vertical_align_centre">
                <?php the_excerpt();?>
            </div>
        </div>
    </div>
    </div>
    <div class="row">
    <div class="col-md-3">
        <?php the_post_thumbnail('casestudy img-responsive');?>
    </div>
    <div class="carousel-row hidden-xs">
            <div class="col-md-9">
            <?php $args = array('post_type' => 'images','posts_per_page' => -1 ); $loop = new WP_Query($args); if( $loop->have_posts() ):  ?>
                <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
                 <!-- Indicators -->
                    <ol class="carousel-indicators">
                        <?php $count_images = wp_count_posts('images'); 
                                $published_images = $count_images->publish;
                                    if(count($published_images) > 0) {
                                        for ($i=0; $i < $published_images; $i++) { ?>
                                            <li data-target="#carousel-example-generic" data-slide-to="<?php echo $i; ?>" <?php if($i == 0){ echo 'class="active"';} ?>></li>
                                        <?php }
                                    }
                        ?>
                    </ol>
    
                <!-- Wrapper for slides -->
                    <div class="carousel-inner">
                    <?php $j = 0; while( $loop->have_posts() ): $loop->the_post(); global $post; ?>
                        <div class="item <?php if($j == 0) { echo 'active'; }?>">
                            <img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>" alt="<?php echo get_the_title(); ?>">
                                <div class="carousel-caption">
                                    <?php the_excerpt(); ?>
                                </div>
                        </div>
                    <?php $j++; endwhile;?>
                    </div>
    
                <!-- Controls -->
                <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
                    <span class="glyphicon glyphicon-chevron-left"></span>
                </a>
                <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right"></span>
                </a>
            </div>
        <?php endif; wp_reset_query(); ?>
            </div>
            </div>
    <?php endwhile; endif; ?>
    
    
    案例研究
    >
    
    它应该做什么?你的问题是什么?我已经更新了问题我已经更改了代码,很抱歉数组没有被实际使用。