【问题标题】:WORDPRESS apply_filters only home pageWORDPRESS apply_filters 仅主页
【发布时间】:2016-05-11 07:01:22
【问题描述】:

我有一个简单的函数(在我的主题中的 functions.php 中),它将类添加到导航链接

   add_filter('next_posts_link_attributes', 'posts_link_attributes');
   add_filter('previous_posts_link_attributes', 'posts_link_attributes');

  function posts_link_attributes() {
     if (is_home() || is_front_page()) {
        if (current_filter() == 'previous_posts_link_attributes') {
            return 'class="prevlink ajax"';
        }
        elseif (current_filter() == 'next_posts_link_attributes') {
            return 'class="nextlink ajax"';
        }
     }
  }

我只需要在我的主页上使用它,但它不起作用。 谁能帮帮我?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    我解决了向 index.php 添加过滤器的问题

    add_filter('next_posts_link_attributes', 'posts_link_attributes');
    add_filter('previous_posts_link_attributes', 'posts_link_attributes');
    

    我不知道这是否正确,但它可以正常工作。会不会有什么问题?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      • 2014-06-03
      相关资源
      最近更新 更多