我想在自定义模板中显示页面。我使用post query loop来显示页面并且它有效。但我不希望主页显示。我想通过ASCENDING订单显示我的页面。我在页面中使用订单。但我无法修复它。
<?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; ?>
你可以帮我解决这个问题。
答案 0 :(得分:0)
您可以通过传递主页ID来排除主页:
$args = array( 'posts_per_page' => 3, 'post_type'=> 'page', 'order' => 'ASC','exclude' => 1);
答案 1 :(得分:0)
您也可以直接进行简单查询:在自定义页面中放置以下代码(替换表名和字段)
<?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>";
?>
答案 2 :(得分:0)
我假设您在设置&gt;中设置了首页。读。如果是这种情况,这应该对你有用:
$front_page = get_option( 'page_on_front' );
$args = array(
'posts_per_page' => 3,
'post_type' => 'page',
'order' => 'ASC',
'post__not_in' => array( $front_page ),
);