WordPress的页面(page)功能是很不错的,可以做成各类专栏,内容等页面,而且每个页面可以自定义不同的样式模板,就像博客导航内页友链都是页面套用不同的模板来实现的,这是一个十分强大而有用的功能。
下面就分享下,让页面支持添加标签和分类,以及在标签存档和分类存档中包含页面的方法。
area data-settings="dblclick" readonly >//为WordPress页面添加标签和分类class PTCFP{ function __construct(){ add_action( 'init', array( $this, 'taxonomies_for_pages' ) ); if ( ! is_admin() ) { add_action( 'pre_get_posts', array( $this, 'category_archives' ) ); add_action( 'pre_get_posts', array( $this, 'tags_archives' ) ); } // ! is_admin } // __construct function taxonomies_for_pages() { register_taxonomy_for_object_type( 'post_tag', 'page' ); register_taxonomy_for_object_type( 'category', 'page' ); } // taxonomies_for_pages function tags_archives( $wp_query ) { if ( $wp_query->get( 'tag' ) ) $wp_query->set( 'post_type', 'any' ); } // tags_archives function category_archives( $wp_query ) { if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) ) $wp_query->set( 'post_type', 'any' ); } // category_archives} // PTCFP$ptcfp = new PTCFP();area>16171819202122232425262728293031323334353637//为WordPress页面添加标签和分类class PTCFP{ function __co
nstruct(){ add_action( 'init', array( $this, 'taxonomies_for_pages' ) ); if ( ! is_admin() ) { add_action( 'pre_get_posts', array( $this, 'category_archives' ) ); add_action( 'pre_get_posts', array( $this, 'tags_archives' ) ); } // ! is_admin } // __co
nstruct function taxonomies_for_pages() { register_taxonomy_for_object_type( 'post_tag', 'page' ); register_taxonomy_for_object_type( 'category', 'page' ); } // taxonomies_for_pages function tags_archives( $wp_query ) { if ( $wp_query->get( 'tag' ) ) $wp_query->set( 'post_type', 'any' ); } // tags_archives function category_archives( $wp_query ) { if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) ) $wp_query->set( 'post_type', 'any' ); } // category_archives} // PTCFP$ptcfp = new PTCFP();