仅在 tumblr 博客主页上显示 div?
我对 CSS 和 HTML 的理解相当新手,我正在尝试做一些我认为应该相对简单的事情(在我正在创建的自定义 tumblr 主题中),但我找不到简单的答案。我有一种感觉,可能有一种超级简单的方法可以在 JavaScript 中完成我想要的事情。
我想仅在 tumblr 博客的主索引页(即主页)上显示 DIV
。 tumblr 提供的文档似乎允许您在某种程度上执行此操作(通过 {Block:IndexPage} 变量),但问题是此元素中的代码显示在所有索引页面上(即而不是只是显示在 /page/1 的根级别上,它将显示在后续的“索引”页面上,例如 /page/2 等。
这是我的代码,它成功地不在永久链接页面上显示 div:
{block:IndexPage}
<div class="mid2">
<div class="midLeft2">
<p>test</p>
</div>
</div>
{/block:IndexPage}
任何想法非常感谢任何帮助!
I have a fairly novice understanding of CSS and HTML, and I'm trying to do something that I think should be relatively simple (in a custom tumblr theme I'm creating), but I can't find a straightforward answer. I have a feeling there might be a super easy way to do what I want in JavaScript.
I'd like to display a DIV
only on the main index page (i.e. homepage) of the tumblr blog. It seems the documentation tumblr provides allows you to do this to some extent (through the {Block:IndexPage} variable), but the problem is the code within this element displays on all index pages (i.e. instead of just showing up at the root level on /page/1, it will show up on subsequent "index" pages like /page/2, etc.
Here's the code I have, which successfully does not show the div on permalink pages:
{block:IndexPage}
<div class="mid2">
<div class="midLeft2">
<p>test</p>
</div>
</div>
{/block:IndexPage}
Any ideas? Any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
这将起作用:
更多信息:http://ejdraper.com/post/280968117/advanced- tumblr 定制
This will work:
More info: http://ejdraper.com/post/280968117/advanced-tumblr-customization
我一直想在帖子页面上显示代码,但不在索引、搜索等页面(即包含多个帖子的页面)上显示代码。感谢上述内容,我想出了如何做到这一点并希望分享,以防它对其他人有帮助。
I was was looking to show code on post pages, but not on the index, search, etc page (i.e. pages with multiple posts. Thanks to the above, I figured out how to do it and wanted to share in case it helps somebody else.
您也可以仅使用 CSS 来完成。
You can also do it just with CSS.
display:none
会隐藏它,但隐藏的元素仍然会扰乱您的布局。我们可以使用注释代码* 将 div 变成不会弄乱任何内容的注释。
前任。
display:none
will hide it but thats, a hidden element can still mess with your layout.We could use the comment code* to turn the div into a comment that wont mess with anything.
ex.
正如您所发现的,
{block:IndexPage}
块适用于所有索引页。要仅定位第一页,您可以在脚本中使用{block:Post1}
内联或{CurrentPage}
。{block:Post1}
只会显示在第一篇帖子的页面上,这就达到了你想要的效果。然后可以对进行样式设置,将其放置在您想要的任何位置。
或者:
The
{block:IndexPage}
block, as you have discovered, is for all index pages. To target only the first page you can use{block:Post1}
inline or{CurrentPage}
in script.{block:Post1}
will display only on the page with the first post, which achieves what you want. The<div>
can then be styled to put it wherever you want.Or:
我最终完全删除了 {Block:IndexPage} 标签,并将原始 div 标注更改为:
后面是这个脚本:
I ended up killing off the {Block:IndexPage} tag altogether and changing the original div callout to this:
Followed by this script:
这是通过使用 div:not() 运算符来解决的。
HTML 标记
现在将此 CSS 添加到
背景:
{CurrentPage}
是一个 Tumblr 主题变量,它返回索引页的页码(如 1、2、3...)。因此,任何 Tumblr 博客的主页都是页码“1”。现在我已经定义了 div 的类,该页码与字符串“banner_”连接(类不能是数字。WTF 为什么?) - 在主页上创建类名称“banner_1”。接下来,在 CSS 中,我将display:none
属性添加到banner_1
类 div 的:not
选择器。因此,除了banner_1
类的 div 之外,#banner
div 下的所有其他 div 都将消失。此外,id 为#banner
的 div 隐藏在搜索和标签页面中。注意:
为必填项。如果没有这个,
:not
将隐藏 html 中的所有 div。警告:IE用户(还有人吗?)需要改变他们的习惯。仅 FF、Chrome、Safari 和 Opera 支持此功能。
我已经在 http://theteazone.tumblr.com/ The Big Banner 中实现了这一点(茶是一种文化) http://theteazone.tumblr.com/page/2 中不存在
This is solved by using div:not() operator.
The HTML Markup will be
Now add this CSS to
The background:
{CurrentPage}
is a Tumblr theme variable which returns the page number of index pages (like 1, 2, 3, ...). Thus the home of any Tumblr blog is page number "1". Now I have defined the class of a div with this page number concatenated with a string "banner_" (Class can not be numeric. WTF why?) - making the class name "banner_1" on homepage. Next, in CSS, I have addeddisplay:none
property to:not
selector of thatbanner_1
class div. Thus excluding div withbanner_1
class, all other div in under#banner
div will disappear. Additionally, div with id#banner
is hidden in search and tag pages.Note:
<div id="#banner" >
is required. Without this,:not
will hide all divs in the html.Warning: IE users (is there anyone left?) need to change their habit. This is only supported in FF, Chrome, Safari and Opera.
I have implemented this in http://theteazone.tumblr.com/ The Big Banner (Tea is a culture) is absent in http://theteazone.tumblr.com/page/2
或者,您可以使用此标签:
{block:HomePage}
。顾名思义,该块仅在主页上呈现(即不在搜索页面、标签页面等上)。
参考:
https://www.tumblr.com/docs/fr/custom_themes
Alternatively, you can use this tag:
{block:HomePage}
.This block renders, as its name implies, on the home page only (ie not on search pages, tag pages etc).
References:
https://www.tumblr.com/docs/fr/custom_themes