Wordpress 如何在页面上添加类别和标签?

Wordpress 如何在页面上添加类别和标签?,wordpress,Wordpress,通过在我的主题目录中创建一个php文件,我已经使用自定义模板生成了页面 比如: <?php * * Template Name: Contact Page */ ?> <html ..... </html> 然后在仪表板上添加一个新页面,选择此新模板 现在如何将标签和类别关联到每个页面? 创建帖子而不是页面是唯一的解决方案吗?这个插件帮我解决了以下问题: 按照标准说明: Upload the plugin files to the /wp-content

通过在我的主题目录中创建一个php文件,我已经使用自定义模板生成了页面 比如:

<?php
 *
 * Template Name: Contact Page
 */
 ?>
 <html ..... </html>
然后在仪表板上添加一个新页面,选择此新模板

现在如何将标签和类别关联到每个页面?
创建帖子而不是页面是唯一的解决方案吗?

这个插件帮我解决了以下问题:

按照标准说明:

Upload the plugin files to the /wp-content/plugins/ directory
Activate the plugin through the 'Plugins' menu in WordPress
Use the setting page of the plugin from Settings > Add Tags And Category For Page.

更好的方法是添加到主题文件夹中的functions.php:

function myplugin_settings() {  
    // Add tag metabox to page
    register_taxonomy_for_object_type('post_tag', 'page'); 
    // Add category metabox to page
    register_taxonomy_for_object_type('category', 'page');  
}
 // Add to the admin_init hook of your theme functions.php file 
add_action( 'init', 'myplugin_settings' );
试试这个:

add_action( 'init', 'wpse34528_add_page_cats' );
function wpse34528_add_page_cats(){
    register_taxonomy_for_object_type('post_tag', 'page');
    register_taxonomy_for_object_type('category', 'page'); 
}

尝试使用已接受的答案,但由于某些原因,它只显示帖子类型,而类别页面中没有显示任何页面。例如/类别/娱乐/

要解决这个问题,我必须这样做:

// add tag and category support to pages
function tags_categories_support_all() {
  register_taxonomy_for_object_type('post_tag', 'page');
  register_taxonomy_for_object_type('category', 'page');  
}

// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
  if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
  if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}

// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');

对于初学者来说,说“下载插件”毫无帮助,因为他们很可能没有下载wordpress,因此无法安装所述插件。下面是一些简短的代码,供像我这样的人使用,他们一直在网络上搜寻一些可以在普通账户的普通页面上工作的东西——即你不是开发人员

首先,确保菜单中的页面设置正确。 您不需要将页面设置为“类别”或“标签”! 这不会给你实际的页面,然后去编辑,所以如果你想添加滑块,文本,介绍,或任何事情,你将无法

然后转到WP Admin>页面 选择要编辑的页面并转到文本编辑器,而不是最右侧的可视化编辑器选项卡

然后通过以下短代码:

[display-posts category="hair,makeup,reviews,beauty" posts_per_page="10" include_date="true" text-decoration: none date_format="F j, Y" order="DESC" include_excerpt="true" wrapper="div" image_size="large"]
&lt;

短代码收集您在博客帖子中指定的特定类别的所有帖子,即我的帖子是头发和美丽。所以很明显,把你的改成合适的。然后,它分配了我的10篇文章的数量,日期按降序排列,带有一张大图和一篇文章的摘录

你能详细说明一下将标签和类别关联到每页的意思吗?您的意思是从特定类别/标签中引入帖子并将其显示在此页面上,还是将此页面作为类别/标签的一部分?此操作应关闭。这是一个副本:@Spencer Cameron thanx,谢谢你的回答:我的意思是这个页面是一个类别/标签的一部分吗!不,这两个问题并不完全相同……在这一个问题中,我想问的是,是否可以从页面添加类别,而不是使用或不使用自定义模板由仪表板生成的帖子。请注意,此插件当前与WP>3.6.1不兼容。最好使用init操作,而不是admin_init操作。当使用admin_init操作时,类别/标签菜单将不会出现在admin_菜单中的页面下。这不仅更好,而且只有当您将其设置为init hook时才有效。不要使用admin_init!一个脚本解决方案,而不是另一个推荐的插件。真的很有用,我是一个php程序员,没有WP经验,这对我帮助很大,添加另一个插件是毫无意义的。与没有评论的公认答案完全相同。还使用不必要的wpse命名约定。也似乎是这个的复制品: