我使用这些代码对评论最多、浏览最多的帖子进行排序
<?php $params = $_GET;
unset($params[\'orderby\']);
unset($params[\'order\']);
unset($params[\'v_orderby\']);
unset($params[\'v_sortby\']);
$url = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
$url = strtok($url, \'?\');
$url =$url.\'?\'.http_build_query($params);
?>
<ul id="sort">
<li <?php if($active == "date"): ?> class="active"<? endif ?>><a href="http://<?php echo
$url ?>">Most Rated</a></li>
<li <?php if($active == "comment"): ?> class="active"<? endif ?>><a href="http://<?php echo $url ?>&orderby=comment_count&order=desc">Most commented </a></li>
<li <?php if($active == "views"): ?> class="active"<? endif ?>><a href="http://<?php echo $url ?>&v_sortby=views&v_orderby=desc">Most viewed </a></li>
</ul>
现在我想对自定义字段“评级”进行排序,因为评级最高的是自定义字段的代码。
<?php
//grab the rating value
$rating = get_post_meta($post->ID, \'rating\', true);
//prints star image
for ($i=1; $i<=$rating; $i++){
echo \'<img src="/images/star.png"/>\';
}
//prints unstar image
for ($i=$rating; $i<10; $i++){
echo \'<img src="/images/unstar.png"/>\';
}
?>
为此,我使用了此代码,但它不起作用。
<a href="http://<?php echo $url ?>&orderby=rating&order=desc">Most Rated</a>