【问题标题】:wordpress : how to add categories and tags on pages?wordpress:如何在页面上添加类别和标签?
【发布时间】:2013-01-14 17:34:55
【问题描述】:

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

<?php
 *
 * Template Name: Contact Page
 */
 ?>
 <html ..... </html>

然后在仪表板上添加一个新页面,选择这个新模板

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

【问题讨论】:

  • 您能否详细说明将标签和类别与每个页面关联 的含义?您的意思是从特定类别/标签中引入帖子并在此页面上显示它们还是让此页面成为类别/标签的一部分?
  • 这应该被关闭。这是一个副本:stackoverflow.com/questions/14324026/…
  • @Spencer Cameron 感谢您的回复:我的意思是“此页面是否属于类别/标签?” !不,这两个问题并不完全相同......在这个问题中,我问是否可以使用或不使用自定义模板从仪表板生成的页面(而不是帖子)添加类别

标签: wordpress


【解决方案1】:

最好在你的主题文件夹中添加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' );

【讨论】:

  • 最好使用init 操作而不是admin_init 操作。使用admin_init 操作时,类别/标签菜单不会出现在admin_menu 的页面下。
  • 这不仅更好——只有将它设置为init钩子才有效。不要使用admin_init钩子
  • 太棒了!一个脚本解决方案,而不是另一个推荐的插件。
  • 真的很有用,我是一个零 WP 经验的 php 程序员,这对我帮助很大,添加另一个插件毫无意义..
【解决方案2】:

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

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

// 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');

【讨论】:

  • 它可以工作,但面包屑缺少类别,如何修复它们?
【解决方案3】:

试试这个:

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'); 
}

【讨论】:

【解决方案4】:

对于很可能不会下载 wordpress 并因此无法安装所述插件的初学者来说,说“下载插件”完全没有帮助。下面是一些简短的代码,供像我这样一直在网上搜寻可以在具有常规帐户的常规页面上实际运行的东西的人使用 - 即您不是开发人员。

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

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

然后通过以下短代码:

[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),日期(按降序排列),带有大图和帖子摘录)

【讨论】:

    【解决方案5】:

    这个插件帮我解决了:

    http://wordpress.org/extend/plugins/add-tags-and-category-to-page/

    使用标准说明:

    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.
    

    【讨论】:

    • 请注意,此插件目前与 WP > 3.6.1 不兼容。
    猜你喜欢
    • 1970-01-01
    • 2017-12-16
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    相关资源
    最近更新 更多