Php 将Wordpress循环顺序从';描述';至';asc&x27;单击或下拉
我是PHP新手,需要做以下工作: •创建一个下拉菜单或链接,在选中或单击时将WordPress循环从“desc”更改为“asc” 以下是我的循环代码:Php 将Wordpress循环顺序从';描述';至';asc&x27;单击或下拉,php,loops,wordpress,Php,Loops,Wordpress,我是PHP新手,需要做以下工作: •创建一个下拉菜单或链接,在选中或单击时将WordPress循环从“desc”更改为“asc” 以下是我的循环代码: <?php global $wp_query; $post; $post_id = $post-> ID; $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; rewind_posts(); $temp = $wp_
<?php
global $wp_query; $post; $post_id = $post-> ID;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
rewind_posts();
$temp = $wp_query;
$wp_query = NULL;
$post_type = 'post'; // change this to the post type you want to show
$show_posts = '20'; // change this to how many posts you want to show
$category_name = 'used-cars'; // change this to the category name you need
$order_by = 'meta_value_num';
$meta_key = 'price';
$order = 'desc'
?>
<?php $wp_query = new WP_Query( 'category_name=' . $category_name . '&post_type=' . $post_type . '&posts_per_page=' . $show_posts . '&paged=' . $paged . '&orderby=' . $order_by . '&meta_key=' . $meta_key . '&order=' . $order ); ?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div style="width: 670px; height: 170px; border-bottom: 3px solid #ccc; width: 100%; padding-top: 20px;">
<!-- POST THUMB -->
<div style="float: left; width: 150px;">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
<?php else : ?>
<div style="width: 150px; height: 150px; border: 1px solid #efefef;">
<p style="text-align: center; margin-top: 60px;">No Pictures Available</p>
</div>
<?php endif; ?>
</div>
<!-- POST CONTENT RIGHT -->
<div style="float: left; margin: 0px 0 0 20px; width: 450px;">
<div style="float: left; width: 245px; height: 150px;">
<!-- POST INNER LEFT -->
<h2 style="margin-bottom: 20px; font-size: 16px;"><a class="loop-link" href="<?php the_permalink() ?>"><?php the_title() ?></a></h2>
<div style="float: left; width: 70px; height: 120px;">
<p style="font-size: 12px;"><strong>Year/Reg:</strong></p>
<p style="font-size: 12px;"><strong>Fuel Type:</strong></p>
<p style="font-size: 12px;"><strong>Colour:</strong></p>
<p style="font-size: 12px;"><strong>Mileage:</strong></p>
<p style="font-size: 12px;"><strong>Gearbox:</strong></p>
</div>
<div style="float: left; width: 70px; height: 120px; text-align:right;">
<p style="font-size: 12px;"><?php the_field('year-reg'); ?></p>
<p style="font-size: 12px;"><?php the_field('fuel_type'); ?></p>
<p style="font-size: 12px;"><?php the_field('colour'); ?></p>
<p style="font-size: 12px;"><?php the_field('mileage'); ?></p>
<p style="font-size: 12px;"><?php the_field('gearbox'); ?></p>
</div>
</div>
<!-- POST INNER RIGHT -->
<div style="float: right; margin: 0; width: 170px; height: 150px; border-left: 1px solid #efefef; text-align: right;">
<h2>Price: <?php the_field('price'); ?></h2>
<br>
<a class="view-button" href="<?php the_permalink(); ?>">VIEW THIS USED CAR</a>
<br>
<br>
<br>
<br>
<!-- SHARE BUTTONS -->
<p>SHARE THIS CAR</p>
<span class='st_facebook'></span>
<span class='st_twitter'></span>
<span class='st_googleplus'></span>
<span class='st_linkedin'></span>
<span class='st_pinterest'></span>
<span class='st_email'></span>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
没有可用图片
年份/Reg:
燃料类型:
颜色:
里程数:
变速箱:
价格:
共用这辆车
代码用于汽车网站,您可以在此处查看该页面:
我已经找了好几天的时间来解决这个问题,但是,我没有找到任何解决方案。同样,正如我所说的,我是PHP新手,所以任何帮助或建议都会很好。网友们,有什么想法吗
Slainté。使用以下代码,现在使用 filename.php?order=desc 或 filename.php?=order=asc 它会随之改变
<?php
global $wp_query; $post; $post_id = $post-> ID;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
rewind_posts();
$temp = $wp_query;
$wp_query = NULL;
$post_type = 'post'; // change this to the post type you want to show
$show_posts = '20'; // change this to how many posts you want to show
$category_name = 'used-cars'; // change this to the category name you need
$order_by = 'meta_value_num';
$meta_key = 'price';
$order = ($_GET["order"]);;
?>
<?php $wp_query = new WP_Query( 'category_name=' . $category_name . '&post_type=' . $post_type . '&posts_per_page=' . $show_posts . '&paged=' . $paged . '&orderby=' . $order_by . '&meta_key=' . $meta_key . '&order=' . $order ); ?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div style="width: 670px; height: 170px; border-bottom: 3px solid #ccc; width: 100%; padding-top: 20px;">
<!-- POST THUMB -->
<div style="float: left; width: 150px;">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
<?php else : ?>
<div style="width: 150px; height: 150px; border: 1px solid #efefef;">
<p style="text-align: center; margin-top: 60px;">No Pictures Available</p>
</div>
<?php endif; ?>
</div>
<!-- POST CONTENT RIGHT -->
<div style="float: left; margin: 0px 0 0 20px; width: 450px;">
<div style="float: left; width: 245px; height: 150px;">
<!-- POST INNER LEFT -->
<h2 style="margin-bottom: 20px; font-size: 16px;"><a class="loop-link" href="<?php the_permalink() ?>"><?php the_title() ?></a></h2>
<div style="float: left; width: 70px; height: 120px;">
<p style="font-size: 12px;"><strong>Year/Reg:</strong></p>
<p style="font-size: 12px;"><strong>Fuel Type:</strong></p>
<p style="font-size: 12px;"><strong>Colour:</strong></p>
<p style="font-size: 12px;"><strong>Mileage:</strong></p>
<p style="font-size: 12px;"><strong>Gearbox:</strong></p>
</div>
<div style="float: left; width: 70px; height: 120px; text-align:right;">
<p style="font-size: 12px;"><?php the_field('year-reg'); ?></p>
<p style="font-size: 12px;"><?php the_field('fuel_type'); ?></p>
<p style="font-size: 12px;"><?php the_field('colour'); ?></p>
<p style="font-size: 12px;"><?php the_field('mileage'); ?></p>
<p style="font-size: 12px;"><?php the_field('gearbox'); ?></p>
</div>
</div>
<!-- POST INNER RIGHT -->
<div style="float: right; margin: 0; width: 170px; height: 150px; border-left: 1px solid #efefef; text-align: right;">
<h2>Price: <?php the_field('price'); ?></h2>
<br>
<a class="view-button" href="<?php the_permalink(); ?>">VIEW THIS USED CAR</a>
<br>
<br>
<br>
<br>
<!-- SHARE BUTTONS -->
<p>SHARE THIS CAR</p>
<span class='st_facebook'></span>
<span class='st_twitter'></span>
<span class='st_googleplus'></span>
<span class='st_linkedin'></span>
<span class='st_pinterest'></span>
<span class='st_email'></span>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
没有可用图片
年份/Reg:
燃料类型:
颜色:
里程数:
变速箱:
价格:
共用这辆车
您是否尝试过(a)创建下拉菜单和/或排序链接,(b)了解如何更改排序顺序,或(c)了解表单的工作方式,以便实现排序顺序的更改?您好,我通过wordpress支持论坛等在线搜索过。我可以创建表单,没有问题。我只需要找出