27

テーマ ディレクトリに次のような php ファイルを作成して、カスタム テンプレートを使用してページを生成しました。

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

次に、この新しいテンプレートを選択してダッシュボードに新しいページを追加します

タグとカテゴリを各ページに関連付けるにはどうすればよいですか? ページの代わりに投稿を作成することが唯一の解決策ですか?

4

5 に答える 5

74

さらに良いのは、テーマフォルダの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' );
于 2013-02-05T15:59:19.690 に答える
16

受け入れられた回答を使用してみましたが、何らかの理由で投稿タイプのみが表示され、カテゴリページにはページが表示されません。例 /category/entertainment/

それを修正するには、これを行う必要があります。

// 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');
于 2016-01-29T14:50:47.237 に答える
1

これを試して:

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'); 
}
于 2015-03-05T17:53:32.363 に答える
-1

このプラグインは私を整理しました:

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.
于 2013-01-21T20:21:59.813 に答える