テーマ ディレクトリに次のような php ファイルを作成して、カスタム テンプレートを使用してページを生成しました。
<?php
*
* Template Name: Contact Page
*/
?>
<html ..... </html>
次に、この新しいテンプレートを選択してダッシュボードに新しいページを追加します
タグとカテゴリを各ページに関連付けるにはどうすればよいですか? ページの代わりに投稿を作成することが唯一の解決策ですか?
テーマ ディレクトリに次のような php ファイルを作成して、カスタム テンプレートを使用してページを生成しました。
<?php
*
* Template Name: Contact Page
*/
?>
<html ..... </html>
次に、この新しいテンプレートを選択してダッシュボードに新しいページを追加します
タグとカテゴリを各ページに関連付けるにはどうすればよいですか? ページの代わりに投稿を作成することが唯一の解決策ですか?
さらに良いのは、テーマフォルダの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' );
受け入れられた回答を使用してみましたが、何らかの理由で投稿タイプのみが表示され、カテゴリページにはページが表示されません。例 /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');
これを試して:
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');
}
このプラグインは私を整理しました:
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.