通常用于类别的wordpress结构如下。 http://ourdomain/category/categoryname/subcategoryname
但我想要我的结构 http://ourdomain/categoryname1/categoryname2/categoryname3
我不知道我能以哪种方式实现这个目标?
我想做的是使用这种网址,它应该进入wp-content中的某个页面。之后代码我将管理。
如果有人对此方向有所了解?
答案 0 :(得分:0)
我不知道你如何在网址中显示3个类别,但要在内容中显示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
答案 1 :(得分:0)
使用以下代码我能够实现这一目标。
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');