Wordpress重写动态网址

时间:2015-07-31 16:44:30

标签: wordpress .htaccess mod-rewrite rewrite add

我希望动态地扩展每个类别的大量产品的Wordpress网站。我有一个url example.com/koelkast页面的类别,我从中检索我数据库中的所有产品:

<?php
global $wpdb;
$databasetabel =  get_post_meta( $post_id, 'database-prefix', true);

$data = $wpdb->get_results("
SELECT *
FROM  $databasetabel  
LIMIT 0, 100;
");

foreach ($data as $info) {
echo '<a href=wp-content/themes/mytheme/tpl_detailpagina.php?cat='.$databasetabel.'&idnummer='.$info->idnummer.'>'.$info->typenummer.'<br>';
    }   
} else
{ 
?>

这很有效,我得到了所有类别产品的清单。当我点击链接时,详细信息页面包含以下网址:

https://www.example.com/wp-content/themes/mytheme/tpl_detailpagina.php?cat=koelkast&idnummer=76

我使用$ _GET来接收正确的详细信息。

但我希望它是例如: example.com/koelkast/miele-w3203 其中miele-w3203是产品名称。

我已经检查了很多教程,但我无法使用它?我是否需要使用Wordpress add_query_vars或者只使用我的.htaccess文件重写它?这里最好的方法是什么?

0 个答案:

没有答案