简而言之,我将一些文章从默认的post-type移动到自定义帖子类型.现在,我的文章可以通过旧的www.example.com/articleurl/和新的www.example.com/blog/articleurl/网址访问.
有一个问题:客户添加了一个带有网址'2093'的文章.它可以使用www.example.com/blog/2093/.但是当我尝试使用www.example.com/2093/wordpress尝试获取2093年或类别的存档(顺便说一下,没有这样的类别),然后重定向到索引页面.
那么如何解决这个问题?
不,我无法更改本文的网址.我需要离开它2093.
是的,我需要我的网站的这个层次结构,我需要自定义帖子类型.
在主题根目录中创建一个名为 archive-2093.php 的文件并添加以下代码:
<?php
$args = array (
'name' => '2093',
'post_type' => array( 'blog' ),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// adapt the following to suit the formatting and fields of your post.
the_title();
the_content();
}
} else {
// oh no, it didn't work.
}
// Restore original Post Data
wp_reset_postdata();
Run Code Online (Sandbox Code Playgroud)
您必须调整循环以匹配您在 single.php 或 blog-single.php 中使用的任何布局和结构。这里的概念是创建 2093 年的特定存档,然后只需执行自定义查询即可返回您的帖子。
请记住在 2093 年更新您的代码。