代码之家  ›  专栏  ›  技术社区  ›  systemdebt

在wordpress中隐藏标签

  •  0
  • systemdebt  · 技术社区  · 7 年前

    我们正在使用公文包插件,并已添加了4个类别。除4个类别外,它还显示 全部的

    为此,需要在标头中添加类似的内容作为附加JS:

    (function($, undefined) {
      $(function() {
        var cats = $('.sort_by_cat .cat');
        cats.filter(':first').hide();
        cats.filter(':nth(1)').find('a').click();
      });
    })(jQuery);
    

    这是我的建议 link 我们的设计师组

    现在,我应该指什么类而不是 .sort_by_cat .cat

    2 回复  |  直到 7 年前
        1
  •  2
  •   ChrisNaylor94    7 年前

    .portfolio-category-tab-filter li:nth-child(1) {
        display: none;
    }
    

    或第一种类型:

    .portfolio-category-tab-filter li:first-of-type {
        display: none;
    }
    

    .portfolio-category-tab-filter li:first-child {
        display: none;
    }
    

    使用CSS意味着在用户禁用JS的情况下,元素仍将隐藏。

    var element_to_hide = document.querySelector('.portfolio-category-tab-filter li:first-of-type');
    
    element_to_hide.parentNode.removeChild(element_to_hide);
    

    或者可以使用jQuery .remove() 它将元素及其内部的所有内容从DOM中取出:

    jQuery('.portfolio-category-tab-filter li:first-of-type').remove();
    
        2
  •  1
  •   Saeed Rahimi    7 年前

    您应该使用css选择器选择该元素并将其从DOM中删除。

    (function($, undefined) {
      $(function() {
        var link= $('.portfolio-lists a[data-filter="*"');
        link.remove()
      });
    })(jQuery);