【问题标题】:Conditional Statement Outside of the Loop in wordpress [in header]wordpress中循环外的条件语句[在标题中]
【发布时间】:2011-12-17 11:48:19
【问题描述】:

在我的 header.php 文件中有一个图像,如果存在自定义字段,我想更改它。如果该字段为空,或者您在 index.php 页面上,则需要有条件。

试了循环外的代码,试了循环内的条件语句,不知道怎么结合

【问题讨论】:

    标签: wordpress loops conditional field


    【解决方案1】:

    这样的事情可能会奏效:

    if (is_page()) {
      $pageid = get_query_var('page_id');
      if (get_post_meta($pageid, '_wp_page_template', true) != 'index.php' &&
         ($custom_field = get_post_meta($pageid, 'custom field name', TRUE)) {
        //code to change image
      }
    }
    

    【讨论】:

    • 也发帖?顺便说一句,谢谢!
    • 不客气。那么它有效吗?如果它必须发生在帖子上,那么需要知道每个帖子是否都有相同的自定义字段
    猜你喜欢
    • 2015-02-10
    • 1970-01-01
    • 2017-03-10
    • 2015-09-28
    • 2011-10-23
    • 2019-03-25
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    相关资源
    最近更新 更多