【发布时间】:2021-01-07 13:41:14
【问题描述】:
- 我使用(Wordpress 自定义帖子类型)创建了一个简单的纪念帖子目录
- 设置已将存档设置为 - TRUE
- 创建了一个single-memorial-wall.php
- 创建了一个archive-memorial-wall.php
一切正常,但 Yoast 无法帮助我的客户进行此存档页面的 SEO,因为它没有可附加到的页面或类别,因此(查看源代码图像)页面标题不正确,没有显示页面的描述详情。
所以我想,我可以对它进行排序,创建一个自定义分类...(下面的代码),然后为这些帖子类型设置此默认值。
然而,通过创建分类,我只是增加了更多不必要的复杂性,客户当然必须创建一个类别类型,并将每个帖子附加到它上面,就像普通帖子一样。 (即使所有自定义帖子都只会进入此分类)。
CPT 的原因是为客户提供一个简单的仪表板,而无需勾选类别,他创建的简单帖子总是附加到正确的类别存档,并且可以通过 SEO 索引。
我在这里遗漏了什么...如果我创建的分类区域不允许进一步分类并且只是 has_archive 的 SEO 所在的地方,那就太好了。
function custom_memorial_post_type()
{
$args = array(
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'exclude_from_search' => true,
'show_in_nav_menus' => false,
'has_archive' => true,
'hierarchical' => true,
'labels' => array(
'name' => 'Memorials',
'singular_name' => 'Memorial',
'add_new' => __('Add A Memorial'),
'add_new_item' => __('New Memorial'),
'edit_item' => __('Edit The Memorial'),
'new_item' => __('New Memorial'),
'all_items' => __('All Memorials'),
'view_items' => __('View Memorials'),
'menu_name' => 'Memorials'
),
'supports' => array(
'title',
'custom-fields',
'post-formats'
),
'description' => 'Pet memorial',
'menu_position' => 22,
'menu_icon' => 'dashicons-format-image',
);
register_post_type('memorial-wall', $args);
}
add_action('init', 'custom_memorial_post_type');
function memorial_wall_taxonomy() {
$args = array(
'labels' => array(
'name' => 'Memorial Wall',
'singular_name' => 'Memorial Wall',
'parent_item' => __('Parent Memorial Wall Category'),
'parent_item_colon' => __('Parent Memorial Wall Category:'),
'edit_item' => __('Edit The Memorial Wall Category'),
'update_item' => __('Update The Memorial Wall Category'),
'add_new_item' => __('Add New Memorial Wall Category'),
'new_item_name' => __('New Memorial Wall Category'),
'menu_name' => 'Memorials Wall SEO'
),
'public' => true,
'hierarchical' => true
);
register_taxonomy('memorial-taxonomy', array('memorial-wall'), $args);
}
add_action( 'init', 'memorial_wall_taxonomy');
【问题讨论】:
标签: php wordpress custom-post-type taxonomy