我想在自定义模板中显示页面。我使用后查询循环来显示页面,它是有效的。但是我不想显示主页。我想按升序显示我的页面。我在页面中使用顺序。但我无法修复它。
<?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; ?>
你能帮我摆脱困境吗。
我假设您在设置>阅读中设置了首页。如果是这样的话,这应该对你有效:
$front_page = get_option( 'page_on_front' );
$args = array(
'posts_per_page' => 3,
'post_type' => 'page',
'order' => 'ASC',
'post__not_in' => array( $front_page ),
);
您可以通过传递主页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>";
?>