2012-01-24 6 views
0

投稿/ページではなく、私の "WPプライベート"プラグインが私のテンプレートを使って動作するのに問題があります。 Googleを検索しているときに、単一文のショートコードを実装する方法を調べるのに問題はありませんが、私が知っているオープン/クローズの短いタグを実装する方法を見つけることができません。ワードプレスのdo_shortcodes

ここに私のコードです。私は別の構文の問題があるはずです!この場合に使用した開閉タグは、私が試した別のウェブサイトで成功していることが証明されています。しかし、この場合は機能しません。

<?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]') ?> 

答えて

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 
}