Onepage with shortcodes

时间:2015-07-28 作者:geeky87

我构建了一个单页wordpress主题,为了在一个页面中显示我的所有页面,我使用了一个循环,但短代码不起作用(例如:联系表单7:表单正在显示但根本不起作用)。这是我的代码:

            <?php
            /*
              Template Name: Pulse one page
             */
            $this_page = $post->ID;
            get_header();
            ?>

            <div class="hs-content-scroller">
                <!-- Header -->
                <div id="header_container">
                    <div id="header">
                        <div><a class="home"><i class="fa fa-home"></i></a>
                        </div>
                        <div><a href="" class="previous-page arrow"><i class="fa fa-angle-left"></i></a>
                        </div>
                        <div><a href="" class="next-page arrow"><i class="fa fa-angle-right"></i></a>
                        </div>
                        <!-- News scroll -->
                        <?php
                        $news_items = ot_get_option(\'header_news\', array());
                        if (!empty($news_items)) {
                            ?>
                            <div class="news-scroll">
                                <span><i class="fa fa-line-chart"></i>RECENT ACTIVITY : </span>
                                <ul id="marquee" class="marquee">
                                    <?php
                                    foreach ($news_items as $news_item) {

                                        echo \'<li><strong>\' . $news_item[\'title\'] . \'</strong>\' . $news_item[\'header_news_content\'] . \'</li>\';
                                    }
                                    ?>


                                </ul>
                            </div>
                        <?php } ?>
                        <!-- End News scroll -->
                    </div>
                </div>
                <!-- End Header -->
                <!-- hs-content-wrapper -->
                <div class="hs-content-wrapper">
                    <?php
                    $args = array(\'order\' => \'ASC\',
                        \'orderby\' => \'menu_order\',
                        \'post_type\' => \'page\',
                        \'post__not_in\' => array($this_page),
                        \'posts_per_page\' => -1,
                    );
                    $the_query = new WP_Query($args);

            // The Loop
                    if ($the_query->have_posts()) :

                        while ($the_query->have_posts()) : $the_query->the_post();
                            $the_sub_query = new WP_Query(array(\'page_id\' => $the_query->post->ID));
                            if ($the_sub_query->is_posts_page) {
                                continue;
                            }
                            $mytemplate = get_post_meta($the_query->post->ID, \'_wp_page_template\', true);
                            $title = $the_query->post->post_title;
                            echo "<article class=\'hs-content\' id=\'section" . $the_query->post->menu_order . "\'>";
                            echo "<span class=\'sec-icon fa " . get_post_meta($the_query->post->ID, \'iconfont-select\', true) . "\'></span>";
                            echo "<div class=\'hs-inner\'>";
                            echo "<span class=\'before-title\'>.0" . $the_query->post->menu_order . "</span>";
                            echo "<h2>$title</h2>";
                            if ($mytemplate != null) {
                                the_content();
                                get_template_part(substr($mytemplate, 0, -4));
                            } else {
                                the_content();
                            }
                            echo "</div>";
                            echo "</article>";

                        endwhile;
                    endif;

            // Reset Post Data
                    wp_reset_postdata();
                    ?>
                </div>
                <!-- End hs-content-wrapper -->
            </div>
            <!-- End hs-content-scroller -->
            <?php get_footer(); ?>

1 个回复
SO网友:Trang

更换所有the_content(); 具有echo do_shortcode(get_the_content());

结束

相关推荐

Apply_Filters(‘the_content’,$Content)与DO_ShortCode($Content)

假设我有一个主题选项或自定义的postmeta文本区域。现在我想执行多个短代码、一般文本、图像等。最佳实践是什么?为什么?选项1:$content = //my text area data; echo apply_filters(\'the_content\', $content); 选项2:$content = //my text area data; echo do_shortcode($content); 请告诉我哪一个是最佳实践,以及为什么。EDIT让我详细描