将内容与图库分开(自定义帖子类型)

时间:2017-08-01 作者:Demetris Lyngas

我有一个php文件(single model.php),它首先在一个div中显示帖子内容,然后在图库中显示。

如何从库中分割内容并以不同的div..显示库。。?

代码如下:

<div class="col-xs-12"> 

<?php the_content();

    $ids = get_post_meta( get_the_ID(), \'scent_model_photos\', true );

    $selected_images = \'\';

    if( !empty($ids) ) {

        foreach ($ids as $key => $value) {

            $selected_images .= $key . \',\';

        }

    }

    echo do_shortcode(\'[gallery columns="3" size="model-gallery" link="file" ids="\' . $selected_images . \'"]\'); ?>

</div>

1 个回复
SO网友:Nuno Sarmento

你可以这样做

<?php

get_header(); ?>

<section id="content">

    <div class="container">

        <?php get_template_part(\'inc/page-title\'); ?>

        <div class="row">

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

                <?php /* Start the Loop */ ?>

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

                    <div class="col-sm-7 post-thumb large-thumbnail">

                        <?php the_post_thumbnail(\'model-full\', array( \'class\' => "img-responsive" )); ?>

                    </div>

                    <div class="col-sm-5 entry-content profile">

                        <?php $properties = get_post_meta($post->ID, \'scent_model_data_repeat_group\', true);

                                    if (!empty($properties)) {   ?>

                            <ul class="profile">

                            <?php foreach ($properties as $value) {    ?>

                                <li class="row">

                                    <div class="col-xs-4 col-lg-3"><strong><?php echo $value[\'title\']; ?></strong></div>

                                    <div class="col-xs-8 col-lg-9"><?php echo $value[\'value\']; ?></div>

                                </li>

                            <?php } ?>

                            </ul>

                        <?php } ?>

                        <div class="col-xs-12">

                            <?php the_content();

                    $ids = get_post_meta(get_the_ID(), \'scent_model_photos\', true);
                    $selected_images = \'\';

                    if (!empty($ids)) {
                        foreach ($ids as $key => $value) {
                            $selected_images .= $key . \',\';
                        }
                    }

                            ?>

                        </div>

                    <div class="col-xs-12">

                      <?php echo do_shortcode(\'[gallery columns="3" size="model-gallery" link="file" ids="<?php echo $selected_images; ?>"]\'); ?>

                    </div>

                    </div>

                <?php endwhile; ?>

                <?php scent_paging_nav(); ?>

            <?php else : ?>

                <?php get_template_part(\'content\', \'none\'); ?>

            <?php endif; ?>

        </div>

    </div>

</section>

结束

相关推荐

Using rules in Posts

我正在为客户设计一个主题。我们只有one post 对于每个TvShow, 在那根柱子里,我们有Seasons 和Episodes. (使用meta_post).现在,我有一个ul 对于filtering seasons 一个用于filtering episodes, 比如《第一季》第三集。但这需要在帖子中添加规则(我不想使用js 为此)。类似于:www.example.com/tvshow-name/season-3/episode4/ 显然,我们不能使用add_rewrite_rule (相信我,我