我不知道在 php 的数组中不能使用 if else 语句。我搜索了stackoverflow,发现速记版本实际上应该可以正常工作。
我试过了,但仍然有错误,页面没有加载,我的代码:
query_posts (array(
($prefooter_order_logic == 'xviews' ? "'v_sortby' => 'views', 'v_orderby' => 'desc'," : "")
'order' => 'DESC',
'orderby' => $prefooter_order_logic,
'posts_per_page' => '10',
'post_type' => 'post',
'category_name' => $prefooter_category_select
));
这不会给我错误:
但它不起作用......
($prefooter_order_logic == 'xviews' ? "
'v_sortby' => 'views',
'v_orderby' => 'desc',
" : "
'order' => 'DESC',
'orderby' => $prefooter_order_logic,
"),
我决定停止玩耍并做最简单的方法:
顺便说一句,如果这是最好的方法,有什么想法吗?或不?
if ($prefooter_order_logic == 'xviews') {
query_posts (array(
'v_sortby' => 'views',
'v_orderby' => 'desc',
'posts_per_page' => '10',
'post_type' => 'post',
'category_name' => $prefooter_category_select
));
} else {
query_posts (array(
'order' => 'DESC',
'orderby' => $prefooter_order_logic,
'posts_per_page' => '10',
'post_type' => 'post',
'category_name' => $prefooter_category_select
));
}