【问题标题】:Wordpress Conditional Tag "If empty"Wordpress 条件标签“如果为空”
【发布时间】:2012-03-07 21:15:03
【问题描述】:

如果可能需要帮助:

我的 wordpress 网站中有一个自定义字段,如果它为空,则不显示输入的 div。

这是我目前所拥有的:

<?php
    $newsquote = $cfs->get('news_story_quote');

    if ( ! empty ( $newsquote ) )
    {
    ?>
    <div class="news-story-quote">

    <p><?php global $cfs; echo $cfs->get('news_story_quote'); ?></p>

    </div><!-- News Story Quote -->
    <?php   }   ?>

自定义字段的调用方式是这样的:&lt;?php global $cfs; echo $cfs-&gt;get('news_story_quote'); ?&gt;

任何帮助将不胜感激

【问题讨论】:

  • 你知道,Wordpress 有一个 SE:wordpress.stackexchange.com
  • 是的,我在那里试过。似乎没有人回答:-(
  • 祝你好运,但你尝试过赏金吗?
  • 我无法得到它。问题是什么?
  • 如果自定义字段 'news_story_quote' 为空,我正在尝试使用 news-story-quote 类隐藏 div

标签: php wordpress conditional-statements


【解决方案1】:

您可能不会在循环中使用the function

$newsquote = $cfs->get('news_story_quote', $post_id);

if ($newsquote) : ?>

    <div class="news-story-quote">

    <p><?php echo $newsquote ?></p>

    </div><!-- News Story Quote -->

<?php endif ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 2020-08-01
    • 2014-10-18
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多