0

我在让我的“WP Private”插件通过我的模板而不是帖子/页面工作时遇到了一些麻烦。在搜索 Google 时,我发现如何实现 SINGLE 短代码没有任何问题,但我无法找到如何实现开/关短标签,我知道这很常见。

这是我的代码。我一定有另一个语法问题!我在这种情况下使用的开始/结束标签在我尝试过的另一个网站上证明是成功的。但在这种情况下它不起作用。

<?php echo do_shortcode ('[protected]
                <!--<h2><?php the_title(); ?></h2>-->

                <ul style="border-bottom: 1px solid #d8d8d8" class="<?php echo  get_option('minimax_list_layout'); ?>">                                         
                <?php 
                    query_posts(array ('post__in' => array( 569))); 

                                    if (have_posts()) : while (have_posts()) : the_post(); 
                ?>

                    <li style="border-bottom: 1px solid #d8d8d8; padding-bottom:20px" class="clearfix">                     
                    <?php if ( get_option('minimax_list_layout') == 'style-two' ) { ?>

                        <h3 style="font-family:nobile; font-weight:normal; font-size:1.8em"><a style="text-decoration:none" title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
                        <cite><?php the_time('d M Y') ?> </cite>
                        <?php if ( has_post_thumbnail() ) { ?>
                        <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_post_thumbnail('thumb_post_wide', 'class=head'); ?></a>
                        <?php } ?>

                        <p style="font-family:nobile; font-size:1.15em"><?php echo ShortenText( $post->post_content, 300 ); ?></p>
                        <a class="detail" href="<?php the_permalink() ?>">Continue reading</a>

                    <?php } else { ?>

                        <?php if ( has_post_thumbnail() ) { ?>
                        <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_post_thumbnail('thumb_post_1'); ?></a>
                        <?php } ?>

                                                                                            <div class="post-summary">
                            <h3 style="font-family:nobile; font-weight:normal; font-size:1.8em"><a style="text-decoration:none" title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
                            <!--<cite style="font-style:normal; font-weight:bold; font-family:nobile"><?php the_time('d M Y') ?> </cite>-->
                            <p style="font-family:nobile; font-size:1.15em"><?php echo ShortenText( $post->post_content, 220 ); ?></p>
                            <a style="font-family:nobile" class="detail" href="<?php the_permalink() ?>">Continue reading</a>
                        </div><!-- end post-summary -->
                                            <?php } ?>
                                                                            </li>       


                <?php endwhile;  ?>

                <?php if (show_posts_nav()) : ?>
                <div id="post-navigation" class="clearfix">
                    <span class="previous"><?php next_posts_link('Older Entries') ?></span>
                    <span class="next"><?php previous_posts_link('Newer Entries') ?></span>
                </div>
                <?php endif; wp_reset_query(); ?>   

                <?php else: ?>
                    <p><?php _e('Sorry, no pages matched your criteria.'); ?></p>
                <?php endif; ?>
                </ul><!-- end posts-list -->
[/protected]') ?>
4

1 回答 1

1

你在这里写了非常奇怪的东西。通过做这个:

echo do_shortcode ('[protected]
                <!--<h2><?php the_title(); ?></h2>-->

您将模板的 php 代码作为字符串提交给函数,然后回显它,但它不会被 PHP 引擎解释。此外,第一个单引号会产生语法错误。您必须启用 ob(输出缓冲),运行模板代码,从缓冲区获取结果,将其包装在您的简码中,然后将结果提交给函数 do_shortcode。

http://www.php.net/ob_starthttp://www.php.net/ob_get_clean

ps:我仍然认为你不需要它。如果您可以使用“if”语句并跳过整个代码部分,为什么在这里需要一个简码?我不知道你在插件中做了什么,但如果你试图隐藏模板的一部分,那么“if”是实现你的想法的最简单方法。

if (check_if_allowed())
{
// your part of template is here
}
于 2012-01-25T00:38:26.757 回答