Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 三元语句和do_短码_Php_Wordpress_Ternary - Fatal编程技术网

Php 三元语句和do_短码

Php 三元语句和do_短码,php,wordpress,ternary,Php,Wordpress,Ternary,我正试图获得一个wordpress主题,以便在主页功能区显示插件短代码的输出,该功能区目前似乎只是从选项设置中提取文本字符串。 我对features.php文件进行了如下修改: <?php global $option_setting; $display_features = false; $meta = get_post_meta( get_the_ID(), 'enable-features',true ); if (isset($option_setting[

我正试图获得一个wordpress主题,以便在主页功能区显示插件短代码的输出,该功能区目前似乎只是从选项设置中提取文本字符串。 我对features.php文件进行了如下修改:

<?php global $option_setting;
    $display_features = false;
    $meta = get_post_meta( get_the_ID(), 'enable-features',true );
    if (isset($option_setting['features-enable']['enabled'])) :
    $enabled = $option_setting['features-enable']['enabled'];

if (((isset($enabled['blog']) ) && is_home() ) 
|| ((isset($enabled['staticpage'])) && is_front_page())
|| ((isset($enabled['posts'])) && is_single())
|| ((isset($enabled['archives'])) && is_archive())
|| ($meta)
|| ((isset($enabled['pages'])) && is_page()))
{
    $display_features = true;
}

if ($display_features) :
    if ( count($option_setting['features-main']) > 0 ) : ?>

    <div id="features-area">
    <div class="container">
        <?php
          $i = 0; foreach ( $option_setting['features-main'] as $features ) {
                    echo "<div class='col-md-4 col-sm-4 feature$i'><figure><div><a href='".esc_url($features['url'])."'><img src='".$features['image']."'><div class='features-caption'><div class='features-caption-title'>".$features['title']."</div>",($i==1 ? "<div class='features-caption-desc'><?php echo do_shortcode('[qemcalendar]'); ?></div></div></a></div></figure></div>" : "<div class='features-caption-desc'>".$features['description']."</div></div></a></div></figure></div>";
            $i++;   }
           ?>
     </div>   
    </div><!--.features-->
<?php endif;
endif;
endif; ?>
第24行是回音,我想我所做的是完全错误的,但我正在努力找出我需要做什么

我一开始用的是if-else,但由于这是在echo中,所以我不太高兴。我意识到我可能试图做一些根本不起作用的事情,但所有的想法都得到了赞赏

谢谢


Lisa

您的文本中有语法错误:

那真是太长了,排队很糟糕。使用以下命令:

echo "<div class='col-md-4 col-sm-4 feature".$i."'>"
    . "<figure>"
    . "<div>"
    . "<a href='".esc_url($features['url'])."'>"
    . "<img src='".$features['image']."'>"
    . "<div class='features-caption'>"
    . "<div class='features-caption-title'>".$features['title']."</div>";
    if ($i==1) { echo "<div class='features-caption-desc'>" . do_shortcode('[qemcalendar]')
    . "</div>"
    . "</div>"
    . "</a>"
    . "</div>"
    . "</figure>"
    . "</div>";
    } else { 
        "<div class='features-caption-desc'>".$features['description']."</div></div></a></div></figure></div>";
    }
但我认为,这更具可读性:

<div class='col-md-4 col-sm-4 feature<?php echo $i; ?>'>
    <figure>
        <div>
            <a href='<?php echo esc_url($features['url']); ?>'>
                <img src='<?php echo $features['image']; ?>'>
                <div class='features-caption'>
                    <div class='features-caption-title'><?php echo $features['title']; ?></div>
                    <?php
                    if ($i == 1) {
                        ?>
                        <div class='features-caption-desc'><?php do_shortcode('[qemcalendar]'); ?></div>
                        <?php
                    } else {
                        ?>
                        <div class='features-caption-desc'><?php echo $features['description']; ?></div>
                        <?php
                    }
                    ?>
                </div>
            </a>
        </div>
    </figure>
</div>

我认为你的问题是双重回声

你回显三元语句是因为你使用了逗号,但你回显了这一点

<?php echo do_shortcode('[qemcalendar]'); ?>
或者说是一致的:

, do_shortcode('[qemcalendar]'),

就足够了。

谢谢,但我仍然收到解析错误:语法错误,意外“;”在第24行的/home/pennybro/public_html/dev/wp content/themes/pbcc/features.php中,使用此建议时出现错误。谢谢。不幸的是,第一个建议没有出错,但是对布局做了一些非常奇怪的事情,我将检查是否缺少div close标记。第二个建议导致了这个错误:Parse error:syntax error,unexpected“我发送的代码没有语法错误。考虑使用IDE,突出显示语法错误行。一定是wordpress中组合的php文件的一个撞击效应。无论如何谢谢。等等,你从来没有关闭过你的三元操作,是吗?太棒了!括号中没有错误,现在我只需要找出为什么wordpress忽略了短代码。我想这是一个主题设计师的问题。谢谢你的帮助,
. do_shortcode('[qemcalendar]') .
, do_shortcode('[qemcalendar]'),