如何在url工作中实现多个类别


how to achive multiple categories in url working?

通常类别的wordpress结构如下。http://ourdomain/category/categoryname/subcategoryname

但我希望我的结构像http://ourdomain/categoryname1/categoryname2/categoryname3

我不知道我能以什么方式实现这件事?

我想做的是使用这种url,它应该进入wp内容中的某个页面。之后我将管理代码。

如果有人对这个方向有一些想法?

我不知道你如何在url中显示这三个类别,但要在内容中显示这3个类别,你可以修改一些主题模板,也许是循环或类别模板,使其显示其中三个:

$args = array('numberposts' => $Nposts, 'category' => $id_cat1);
$cat1_posts = get_posts($args);
//Loop to write all posts
$args = array('numberposts' => $Nposts, 'category' => $id_cat2);
$cat2_posts = get_posts($args);
//Loop to write all posts
$args = array('numberposts' => $Nposts, 'category' => $id_cat3);
$cat3_posts = get_posts($args);
//Loop to write all posts

通过以下代码,我能够实现这一点。

function site_router() {
global $route,$wp_query,$window_title;
$bits =explode("/",$_SERVER['REQUEST_URI']);
$route->class = $bits[1];
$route->method = $bits[2];
$route->prop1 = $bits[3];
$route->prop2 = $bits[4];
$route->prop3 = $bits[5];
$route->prop4 = $bits[6];
print_r($bits);
if ( $wp_query->is_404 ) {
$wp_query->is_404 = false;
include(get_template_directory() . "/home.php" ); // replace path_to_classes with the actual directory where you keep your class files
/* at the end of your classfile include, you can create the object as $myObject = new Class */
//$myObject->$route->method($route->prop1); // after calling the method, you can set a property in the object for the template
$template = locate_template('ur path/home.php');
$window_title = 'dynamically it will come';
if ($template) {
load_template($template);
die;
}
}
}
add_action( 'wp', 'site_router');