Php 如何在查询后Wordpress中按顺序显示页面
我想在自定义模板中显示页面。我使用post查询循环来显示页面,它可以正常工作。但我不想在主页上显示。我想按升序显示我的页面。我在页面中使用顺序。但我无法修复它Php 如何在查询后Wordpress中按顺序显示页面,php,html,wordpress,Php,Html,Wordpress,我想在自定义模板中显示页面。我使用post查询循环来显示页面,它可以正常工作。但我不想在主页上显示。我想按升序显示我的页面。我在页面中使用顺序。但我无法修复它 <?php global $post; $args = array( 'posts_per_page' => 3, 'post_type'=> 'page', 'order' => 'ASC'); $myposts = get_posts( $args ); if (!empty($myposts)) : fore
<?php
global $post;
$args = array( 'posts_per_page' => 3, 'post_type'=> 'page', 'order' => 'ASC');
$myposts = get_posts( $args );
if (!empty($myposts)) :
foreach( $myposts as $post ) : setup_postdata($post); ?>
<section class="col-1-3">
<div class="wrap-col">
<div class="box">
<div>
<h2><?php the_title(); ?></h2>
<figure><img src="<?php echo get_template_directory_uri();?>/images/page1_img1.jpg" alt="" ></figure>
<p class="pad_bot1"><?php echo excerpt('20'); ?>...</p>
<a href="<?php the_permalink(); ?>" class="button1">Read More</a>
</div>
</div>
</div>
</section>
<?php endforeach; ?>
<?php else : ?>
default data
<?php endif; ?>
您能帮我解决这个问题吗。您可以通过传递主页id来排除主页:
$args = array( 'posts_per_page' => 3, 'post_type'=> 'page', 'order' => 'ASC','exclude' => 1);
您还可以右键执行简单查询:将下面的代码替换为自定义页面中的表名和字段
<?php
global $wpdb;
$customers = $wpdb->get_results("SELECT * FROM yourtablename Where id = 1 ORDER BY `yourtablename`.`date` ASC");
// add code to limit / exclude .. what you want
echo "<table>";
foreach($customers as $customer){
echo "<tr>";
echo "<td>".$customer->title."</td>";
echo "<td>".$customer->desc."</td>";
echo "<td>".$customer->url."</td>";
echo "</tr>";
}
echo "</table>";
?>
我假设你在设置>阅读中设置了头版。如果是这样的话,这应该对您有用:
$front_page = get_option( 'page_on_front' );
$args = array(
'posts_per_page' => 3,
'post_type' => 'page',
'order' => 'ASC',
'post__not_in' => array( $front_page ),
);
是否要删除要显示的主页?是的,我想从列表中删除并按升序显示其他页面,因为我在页面中使用顺序。在顺序和排除之间,您缺少:$args=array'posts\u per\u page'=>3,'post\u type'=>page','order'=>ASC','exclude'=>1';我使用这个,但这里没有更改。1订单号是否确实存在排除参数?是排除参数是否存在。您可以在这里查看,我无法理解它的简单PHP/MYSQL格式。。您可以修改自己的查询并从多个表中获取记录。。。以上只是在插件的支持页面中询问的示例。我从未用过它