Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hexo可以实现判断某个分类么? #1278

Closed
naog opened this issue May 17, 2015 · 4 comments
Closed

hexo可以实现判断某个分类么? #1278

naog opened this issue May 17, 2015 · 4 comments
Labels
feature-request question Needs help in usage
Milestone

Comments

@naog
Copy link

naog commented May 17, 2015

例如wordpress的is_category()函数可以实现这样的效果:如果是分类A,则显示一段与A相关的简介。
hexo的is_category()辅助函数可以实现么?

@wudong
Copy link

wudong commented May 26, 2015

@naog
Copy link
Author

naog commented Jun 2, 2015

hexo的is_category()只能判断是否是分类归档页面,而不能判断是某个分类(分类A/分类B)的页面。

@tommy351
Copy link
Member

tommy351 commented Jun 5, 2015

You can use page.category to get the category name.

@tommy351 tommy351 added the question Needs help in usage label Jun 5, 2015
@tommy351 tommy351 added this to the 3.2 milestone Jun 11, 2015
@tommy351 tommy351 mentioned this issue Jun 11, 2015
8 tasks
@note4
Copy link

note4 commented Nov 10, 2023

下面两个方法,一个是在列表外使用,一个是在列表内使用,<% page.posts 内既是列表内容,反之既是列表外

以下示例,如果当前列表的分类是网页截图就添加这段行内样式(也可以替换其他任意内容)

<% if (is_category('网页截图')) { %> style="columns: 600px;" <% } %>

这段代码可以在文章页模板使用,也可以在各列表使用

用分类名称name判断,将像素教程替换为特定分类名称

<% post.categories.forEach(category => { %>
	<% if (category.name == '像素教程') { %>
		这是像素教程的内容
	<% } %>
<% }); %>

more: Hexo 笔记 | 像素教程 1px.run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request question Needs help in usage
Projects
None yet
Development

No branches or pull requests

4 participants