前面我们讲到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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
猜你喜欢
  • 2022-02-09
  • 2022-12-23
  • 2021-09-05
  • 2022-02-19
  • 2021-12-27
  • 2022-12-23
相关资源
相似解决方案