【问题标题】:Hide posts from index page从索引页面隐藏帖子
【发布时间】:2020-01-29 19:23:32
【问题描述】:

我试图从我的博客的索引页面中隐藏#old。我仍然想在搜索时看到这些帖子。

我已关注 sorrism 的 tutorial 关于如何从索引页面隐藏标签。我想知道为什么它不能正常工作?我也尝试过 Chloe 的 tutorial,但如果我在我的博客上 nowhere 显示了这个 result,最终会得到它。我在 Chloe 的教程中尝试了后者的 css 代码,但一切看起来好像没有隐藏标签。

{block:IndexPage}.hide-old {display:none;}{/block:IndexPage}</style>
<body><article class="posts hide-{TagsAsClasses}">blah blah</article><script 
src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script> 
$(document).ready(function(){
switch(window.location.pathname) {
    case "/tagged/old":
    $('article').removeClass('hide-old');
    break;
} 
});
 </script></body>

https://pastebin.com/FX1QJH5X(来自 sorrism 的教程)

.old {
display:none;
padding:10px!important;
width:450px!important;
} </style>
<body>
   <div class="posts{block:IndexPage}{TagsAsClasses}{/block:IndexPage}">

https://pastebin.com/Hh3gDAaM(来自 Chloe 的教程)

【问题讨论】:

  • 你能发布一个指向你的 tumblr 的链接吗?很难看到这里发生了什么。看起来您正在设置.hide-old {display:none} 和hide-{TagsAsClasses},如果它存在,它可能也会传入 hide-old,然后您的 jQuery 正在尝试删除该类名。同样&lt;div class="posts{block:IndexPage}{TagsAsClasses}{/block:IndexPage}"&gt; 将连接类名postshide-old,因为 tumblr 块之间没有空格。另外{block:indexPage}不仅仅是首页,它指的是任何索引类型的页面。
  • 我的 tumblr 是 byrdy.tumblr.com。
  • 我还在做一些挖掘,但在这篇文章中:byrdy.tumblr.com/post/179770158829/… 你有以下类名posts hide-to_delete_later old reblog 这意味着类hide-old 永远不存在。我认为您需要一个特定的标签,并且不要使用连接方法,例如带有indexHide 的帖子。我这样做的方法是将类名实际传递给主页。稍后我会发布一个链接,因为我已经写了应该更简单的答案。

标签: jquery css hide tumblr tumblr-themes


【解决方案1】:

好的,这就是我要剥皮的方式。

将这段 javascript 添加到模板的底部。

$(document).ready(function(){
   const addHTMLClass = function() {
      const doc = $('html');
      const primaryDir = document.location.pathname.split('/')[1]; // get the first directory
      if(!primaryDir) { // if there is no primary directory we should be on the home page right?
         doc.addClass('indexPage'); // add a unique classname to the home page only
      }
   }();
});

然后是一些简单的css:

.indexPage .hide-old { // or add your own tag/class name here
    display: none;
}

对于.hide-old 类,你可以使用任何你想要的类名,但它必须是你想要隐藏的那些帖子的标签,但不能使用 tumblr 连接方法,因为这可能会传递不可预测的类名。

我认为这可以满足您的所有需求,它并不完美,因为有些极端情况可能会失败,但这绝对是一个开始。

【讨论】:

    猜你喜欢
    • 2016-11-11
    • 1970-01-01
    • 2014-07-19
    • 2017-06-11
    • 2011-02-26
    • 2012-09-08
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    相关资源
    最近更新 更多