2012-01-24 3 views
0

내 "WP Private"플러그인이 게시물/페이지가 아닌 내 템플레이트를 통해 작동하는 데 문제가 있습니다. Google을 검색 할 때 단일 단축 코드를 구현하는 방법을 찾는 데 아무런 문제가 없지만 매우 일반적인 공통점 인 여는/닫기 닫기 태그를 구현하는 방법을 찾을 수 없습니다.Wordpress의 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

추신 : 나는 여전히 당신이 그것을 필요로하지 않는다는 것을 생각한다. "if"문을 사용할 수 있고 코드의 전체 섹션을 건너 뛰는 이유는 무엇입니까? 나는 당신이 당신의 플러그인에서 무엇을하는지 모르지만 템플릿의 일부를 숨기려고한다면 "if"가 당신의 아이디어를 구현하는 가장 쉬운 방법이다.

if (check_if_allowed()) 
{ 
// your part of template is here 
}