【问题标题】:Wordpress - If Statement function - multiple post typesWordpress - If 语句功能 - 多种帖子类型
【发布时间】:2020-01-15 07:05:50
【问题描述】:

我正在一个名为“库”的帖子类型模板上显示地图。这是我当前代码的“部分”:

if($map_key && is_singular( 'libraries' )) {
        wp_enqueue_script('gmap', 'https://maps.googleapis.com/maps/api/js?key=' . $map_key);
}

现在我添加了另外 2 种帖子类型 - “餐厅”和“酒吧”,因此我还需要为这些单个帖子模板启用地图。

一开始我是这样做的:

if($map_key && is_singular( 'libraries', 'restaurants', 'bars' )) {
        wp_enqueue_script('gmap', 'https://maps.googleapis.com/maps/api/js?key=' . $map_key);
}

但这似乎不起作用。

我怎样才能做到这一点?

【问题讨论】:

  • is_singular(['libraries', 'restaurants', 'bars'])?

标签: php arrays wordpress if-statement


【解决方案1】:

知道了,添加array

is_singular(array('libraries', 'restaurants', 'bars'))

参考:https://developer.wordpress.org/reference/functions/is_singular/

【讨论】:

    猜你喜欢
    • 2013-10-22
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    相关资源
    最近更新 更多