wordpress调用指定id的page页面的方法,适用于多id调用

前面我们讲到wordpress如何调用指定page页面内容,现在再用另外的方法来调试一下,可以直接在single.php模板使用,同样可以调用多id,随ytkah一起来看看

<?php
                        $args = array(
                            'include' => '673,23',//调用指定id,可以多id
                            'post_type' => 'page',
                            'post_status' => 'publish'
                        );
                        $pages = get_pages($args);
                        foreach ( $pages as $post ) : setup_postdata( $post ); ?>
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                        <?php endforeach;
                        wp_reset_postdata();
                        ?>

  详细的参数

<?php $args = array(
	'posts_per_page'   => 5,
	'offset'           => 0,
	'cat'         => '',
	'category_name'    => '',
	'orderby'          => 'date',
	'order'            => 'DESC',
	'include'          => '',
	'exclude'          => '',
	'meta_key'         => '',
	'meta_value'       => '',
	'post_type'        => 'post',
	'post_mime_type'   => '',
	'post_parent'      => '',
	'author'	   => '',
	'author_name'	   => '',
	'post_status'      => 'publish',
	'suppress_filters' => true,
	'fields'           => '',
);
$posts_array = get_posts( $args ); ?>

  参考资料:https://codex.wordpress.org/Function_Reference/get_posts

原文地址:https://www.cnblogs.com/ytkah/p/11751450.html