我的 wordpress 插件中有以下情况:我有一个数据库条目的详细信息页面,可以这样访问:
http://localhost:8888/studio/wp-admin/admin.php?page=myplugin-details&id=42
接下来是向此页面添加排序选项,我用以下代码解决了它:
网址将是:
http://localhost:8888/studio/wp-admin/admin.php?page=myplugin-details&id=42&orderby=answer&order=asc
<?php
if (!empty($_GET['orderby'])) {
$pos = strpos($_SERVER["REQUEST_URI"], 'orderby');
$url = substr($_SERVER["REQUEST_URI"], 0, $pos-1);
if ($_GET['order'] == 'desc') {
echo '<th class="sortable desc">';
echo '<a href="'.$url.'&orderby=answer&order=asc">';
} else {
echo '<th class="sortable asc">';
echo '<a href="'.$url.'&orderby=answer&order=desc">';
}
} else {
echo '<th class="sortable desc">';
echo '<a href="'.$_SERVER["REQUEST_URI"].'&orderby=answer&order=asc">';
}
?>
这工作正常,但我必须做那个 URL/REQUEST_URI 的东西还是有一个更简单的解决方案?
谢谢!