【发布时间】:2021-04-05 06:20:26
【问题描述】:
请有人建议我最好的行动方案。
我为一位专门从事安乐死的兽医创建了一个自定义 wordpress 主题,他想要一个简单的联系表样式的纪念墙,以添加客户缩略图和几行纪念文本。
所以我创建了一个 wordpress 目录 (single-memorial.php),它显示了 (archive-memorial.php) 上的自定义帖子。到目前为止一切顺利...
但我只希望 ARCHIVE 被编入索引并可以查看。不是single-memorial.php
在循环中,我不会在任何 the_permalinks 中包装帖子图块。所以缩略图没有链接到单个帖子数据,基本上使单个帖子完全孤立,除非你当然猜到了 slug 并直接找到了它们。
但是,单个帖子将是可索引的,不是吗,这是我不想要的,我不想不必要地设置 single-memorial.php 的样式 - 因为我不希望任何人看到它们.
如果信息这么少,它们就不是相关页面。
那么我怎样才能公开发布数据,这样 ARCHIVE 才能工作,但不显示 single-memorial.php 页面?
我正在考虑在函数文件中使用 single-memorial.php 将任何单个帖子的某种通用 301 重定向到 ARCHIVE 或 HOME??
我可以进行 .htaccess 重定向,但我不确定如何定位正确的帖子,因为我不知道客户创建的 URL 并添加了新的纪念物。
欢迎提出建议,提前致谢。
// Memorials Custom Post Type
function memorials_custom_post() {
$args = array(
'labels' => array(
'name' => 'Memorials',
'singular_name' => 'Memorial'
),
'show_ui' => true,
'show_in_nav_menus' => true,
'has_archive' => true,
'supports' => array(
'title', 'editor', 'thumbnail', 'post-formats'),
'description' => 'Pet memorial catalogue',
'hierarchical' => true,
'show_in_nav_menus' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'menu_position' => 23,
'menu_icon' => 'dashicons-format-quote'
);
register_post_type( 'memorial-wall', $args );
}
add_action( 'init', 'memorials_custom_post' );
// Redirect Memorial Single Custom Post
function redirect_single_memorial_post() {
if ( is_singular( 'memorial' )) {
wp_redirect( get_post_type_archive_link( 'memorial-wall' ), 301 );
exit;
}
}
add_action( 'template_redirect', 'redirect_single_memorial_post' );
【问题讨论】:
标签: wordpress redirect archive