Php Tab Shortcode 之间的代码

Php code between Tab Shortcode

我想在 tabby 选项卡短代码之间插入 php 代码。

我正在为选项卡视图使用插件 tabby tab,并在我的主题模板中添加了以下代码:

<?php echo do_shortcode('[tabby title="Gallary Name"]
  name content 
  [tabby title="Images"]

  [tabbyending]'); ?>

我想使用如下代码在图像选项卡下使用自定义字段库:

    <?php echo do_shortcode('[tabby title="Gallary Name"]
  name content 
  [tabby title="Images"]

<?php 
$i = 0;
$images = get_field('vil_pics');
if( $images ): ?>
 <div>
   <ul>
        <?php foreach( $images as $image ): ?>
            <li<?php if ( $i % 3 == 0 ) echo ' class="break"' ?>>
                <a href="<?php echo $image['url']; ?>">
                     <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
                </a><p>.</p>
                            </li>
        <?php endforeach; ?>
    </ul></div> 
<?php endif; ?>

[tabbyending]'); ?>

此代码无效,显示的是空白页。我该如何解决这个问题?

Tabby 使用全局变量来跟踪正在发生的事情,因此我认为其中任何一个都可以。第一个简单一点,但是第二个肯定可以。

选项 1: 按顺序输出所有内容:

echo do_shortcode( '[tabby title="Gallery Name"] name content' );
echo do_shortcode( '[tabby title="Images"]' );

// your php code as-is
$i = 0;
$images = get_field('vil_pics');
if( $images ): ?>
  <div>
    <ul>
        <?php foreach( $images as $image ):
          $i++ ?>
          <li<?php if ( $i % 3 == 0 ) echo ' class="break"' ?>>
            <a href="<?php echo $image['url']; ?>">
              <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
            </a><p>.</p>
          </li>
        <?php endforeach; ?>
    </ul>
  </div> 
<?php endif;

echo do_shortcode( '[tabbyending]' );

或选项 2: 将所有内容保存到一个变量并一次性输出:

$output = '';

$output .= '[tabby title="Gallery Name"] name content';
$output .= '[tabby title="Images"]';

$i = 0;
$images = get_field('vil_pics');
if ( $images ) {
  $output .= '<div><ul>';
    foreach( $images as $image ) {
      $i++;
      $li_class = ( $i % 3 == 0 ) ? ' class="break"' : '';

      $output .= '<li' . $li_class . '>';
      $output .= '<a href="' . $image['url'] . '">';
      $output .= '<img src="' . $image['sizes']['thumbnail'] . '" alt="' . $image['alt'] . '" />';
      $output .= '</a><p>.</p></li>';
    }
  $output .= '</div></ul>';
}

$output .= '[tabbyending]';

echo do_shortcode( $output );

请注意,我没有看到任何增加的东西 $i,所以我添加了它。其他一切都是原样。