Wordpress 在短代码中使用IF语句会破坏主题

Wordpress 在短代码中使用IF语句会破坏主题,wordpress,shortcode,Wordpress,Shortcode,我已经设置了一个带有多个选项的滑块短码,这是一个标题,使用自定义帖子类型的滑块的元框来提供选项,如是否显示标题、标题文本等。基本上在我使用的地方 if ( $captionCheckbox !== '1') { 到 endif; $slider.=''; if和endif之间的一切都破坏了主题,但我不明白为什么,这里是完整的短代码,如果它有帮助的话 function ls_slider_shortcode( $atts, $content = null ) { $slider = '<

我已经设置了一个带有多个选项的滑块短码,这是一个标题,使用自定义帖子类型的滑块的元框来提供选项,如是否显示标题、标题文本等。基本上在我使用的地方

if ( $captionCheckbox !== '1') {

endif;
$slider.='';
if和endif之间的一切都破坏了主题,但我不明白为什么,这里是完整的短代码,如果它有帮助的话

function ls_slider_shortcode( $atts, $content = null ) {

$slider = '<section id="slider" class="flexslider container clearfix">';

    $slider .= '<ul class="slides">';

        $sliderQuery = "post_type=slider";

        query_posts( $sliderQuery );


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

            $slideImage = get_the_post_thumbnail( $post->ID, 'slider');


            $slider .= '<li>';
                $slider .= $slideImage;

                $captionCheckbox = get_post_meta( get_the_id(), 'ls_show_slider_caption', true);
                $productCheckbox = get_post_meta( get_the_id(), 'ls_show_button_link', true);
                $position        = get_post_meta( get_the_id(), 'ls_caption_position', true);
                $heading         = get_post_meta( get_the_id(), 'ls_caption_heading', true);
                $text            = get_post_meta( get_the_id(), 'ls_caption_text', true);
                $productLink     = get_post_meta( get_the_id(), 'ls_project_link', true);

                    if ( $captionCheckbox !== '1' ) {

                        $slider .= '<div class="caption' . $position . '>';
                            $slider .= '<div class="body">';
                                $slider .= '<h2 class="caption-title">' . $heading . '</h2>';
                                $slider .= '<p>' . $text . '</p>';
                            $slider .= '</div>';

                            if ( $captionCheckbox !== '1' ) {
                                $slider .= '<a href="' . $productLink .'">View Project</a>';
                            }

                            endif;

                        $slider .= '</div>'
                    }

                    endif;

            $slider .= '</li>';

        endwhile; endif; wp_reset_query();

    $slider .= '</ul>';

$slider .= '</section>';

return $slider;


}

add_shortcode('slider', 'ls_slider_shortcode');
函数ls\u slider\u shortcode($atts,$content=null){ $slider=''; $slider.='
    '; $sliderQuery=“post\u type=slider”; 查询帖子($sliderQuery); if(have_posts()):while(have_posts()):the_post(); $slidemage=get_the_post_缩略图($post->ID,'slider'); $slider.='
  • '; $slider.=$slideImage; $captionCheckbox=get_post_meta(get_id(),'ls_show_slider_caption',true); $productCheckbox=get_post_meta(get_id(),'ls_show_button_link',true); $position=get_post_meta(get_id(),'ls_caption_position',true); $heading=get_post_meta(get_id(),'ls_caption_heading',true); $text=get_post_meta(get_id(),'ls_caption_text',true); $productLink=get\u post\u meta(get\u id(),'ls\u project\u link',true); 如果($captionCheckbox!==“1”){
    $slider.='在此表单中,您需要使用大括号或使用冒号打开要用
    endif
    关闭的块:

    <?php if ( $captionCheckbox !== '1'): ?>
    
      // do stuff
    
    <?php endif; ?>
    
    
    //做事
    
    如果使用大括号,右大括号就足够了

    <?php if ( $captionCheckbox !== '1') { ?>
    
      // do stuff
    
    <?php } ?>
    
    
    //做事
    
    函数ls\u滑块\u短码($atts,$content=null){
    $slider='';
    $slider.='
      '; $sliderQuery=“post\u type=slider”; 查询帖子($sliderQuery); if(have_posts()):while(have_posts()):the_post(); $slidemage=get_the_post_缩略图($post->ID,'slider'); $slider.='
    • '; $slider.=$slideImage; $captionCheckbox=get_post_meta(get_id(),'ls_show_slider_caption',true); $productCheckbox=get_post_meta(get_id(),'ls_show_button_link',true); $position=get_post_meta(get_id(),'ls_caption_position',true); $heading=get_post_meta(get_id(),'ls_caption_heading',true); $text=get_post_meta(get_id(),'ls_caption_text',true); $productLink=get\u post\u meta(get\u id(),'ls\u project\u link',true); ?>
      嘿,伙计,谢谢你的回复。我对php不太熟悉,所以我为我遗漏的任何东西道歉。我想我已经按照你说的内容正确地编辑了这个,但是它仍然不能工作?由于字符限制,我已经用代码回答了下面的问题。我想里面有一个额外的
      endif
      (关闭滑块的上方两行)
      <?php if ( $captionCheckbox !== '1') { ?>
      
        // do stuff
      
      <?php } ?>
      
      function ls_slider_shortcode( $atts, $content = null ) {
      
      $slider = '<section id="slider" class="flexslider container clearfix">';
      
          $slider .= '<ul class="slides">';
      
              $sliderQuery = "post_type=slider";
      
              query_posts( $sliderQuery );
      
      
              if ( have_posts() ) : while ( have_posts() ) : the_post();
      
                  $slideImage = get_the_post_thumbnail( $post->ID, 'slider');
      
      
                  $slider .= '<li>';
                      $slider .= $slideImage;
      
                      $captionCheckbox = get_post_meta( get_the_id(), 'ls_show_slider_caption', true);
                      $productCheckbox = get_post_meta( get_the_id(), 'ls_show_button_link', true);
                      $position        = get_post_meta( get_the_id(), 'ls_caption_position', true);
                      $heading         = get_post_meta( get_the_id(), 'ls_caption_heading', true);
                      $text            = get_post_meta( get_the_id(), 'ls_caption_text', true);
                      $productLink     = get_post_meta( get_the_id(), 'ls_project_link', true);
      
                          ?>
      
                          <?php if ( $captionCheckbox !== '1' ): ?>
      
                              <?php
      
                              $slider .= '<div class="caption' . $position . '>';
                                  $slider .= '<div class="body">';
                                      $slider .= '<h2 class="caption-title">' . $heading . '</h2>';
                                      $slider .= '<p>' . $text . '</p>';
                                  $slider .= '</div>';
      
                                  ?>
      
                                  <?php if ( $captionCheckbox !== '1' ): ?>
                                      <?php $slider .= '<a href="' . $productLink .'">View Project</a>'; ?>
                                  <?php endif; ?>
      
      
      
                              <?php endif; ?>
      
                              <?php
      
                              $slider .= '</div>'
      
                              ?>
      
      
                          <?php endif; ?>
      
                          <?php
      
                  $slider .= '</li>';
      
              endwhile; endif; wp_reset_query();
      
          $slider .= '</ul>';
      
      $slider .= '</section>';
      
      return $slider;
      
      
      }