如何获取自定义分类模板?
我在 WordPress 中有一个类别页面,它有自己的模板 categories.php
,它实际上是一个静态页面,其中包含链接到特定类别的框。这是一个简短的代码:
<?php
/*
Template Name: Categories
*/
?>
<?php get_header(); ?>
<nav><?php wp_nav_menu(array('menu' => 'Main Nav Menu')); ?></nav>
<div id="main-content-categories">
<h5 class="inner_text_shadow">Categories & Tags</h5>
<div id="clear-box">
<a href="/category/locations"><div id="cc" class="c1"><h6>The Fall Locations</h6></div></a>
<a href="/category/info"><div id="cc" class="c2"><h6>Info</h6></div></a>
<a href="/category/budget"><div id="cc" class="c3"><h6>Budget</h6></div></a>
</div> <!-- END main-content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
CSS 并不重要。
我的问题是 - 哪个 PHP 文件/模板用于特定类别(例如 www.mywebsite.com/category/budget
)中的帖子?当我单击任何一个框时,我确实会收到该类别中的帖子,但没有格式设置,只有页眉、侧边栏和页脚。 “来自类别的帖子”的实际代码是什么?我应该将其输入到哪个 PHP 文件中?
[同样的问题也适用于标签。 (www.mywebsite.com/tag/food
)]
I have a categories page in Wordpress and it has its own template categories.php
, which is actually a static page with boxes that link to specific categories. This is a shortened code:
<?php
/*
Template Name: Categories
*/
?>
<?php get_header(); ?>
<nav><?php wp_nav_menu(array('menu' => 'Main Nav Menu')); ?></nav>
<div id="main-content-categories">
<h5 class="inner_text_shadow">Categories & Tags</h5>
<div id="clear-box">
<a href="/category/locations"><div id="cc" class="c1"><h6>The Fall Locations</h6></div></a>
<a href="/category/info"><div id="cc" class="c2"><h6>Info</h6></div></a>
<a href="/category/budget"><div id="cc" class="c3"><h6>Budget</h6></div></a>
</div> <!-- END main-content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
CSS doesn't matter.
My question is - which PHP file/template is used for those posts that are in certain category like www.mywebsite.com/category/budget
? When I click any of the boxes I do get the posts that are in that category but there's no formatting, just the header, sidebar and footer. What is the actual code for "posts from category" and what PHP file do I input it to?
[Same question goes for tags. (www.mywebsite.com/tag/food
)]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
category.php 可以处理所有类别。请参阅下面的示例:
您还可以为每个类别创建单独的文件,格式为category-slug.php。在你的情况下,你会有category-locations.php,category-info.php & category-budget.php
希望这有帮助。
The category.php can handle all categories. See my example below:
You can also have separate files for each category in the format category-slug.php. In your case you would have category-locations.php, category-info.php & category-budget.php
Hope this helps.