在wordpress的首页上显示特定的帖子标题

时间:2017-04-27 10:46:45

标签: wordpress

我想在前面的静态页面中显示特定的帖子标题/内容。记住并非所有帖子都是特定的。所以任何人都可以指导我如何做到这一点..

2 个答案:

答案 0 :(得分:1)

是的,您可以通过在include参数中传递带有数组的帖子ID来获取首页中的特定帖子,

<ul>
<?php

global $post;
$args = array(
 'offset'=> 1,
 'include' => array(1,2,3)  // PASS POST ID IN ARRAY
 'post_type' => 'post', );

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php the_content(); ?>
    </li>
<?php endforeach; 
wp_reset_postdata();?>

</ul>

希望这有效。

答案 1 :(得分:0)

<?php 
  $titles=array();
  $contents=array();
  $links=array();
  // the query
  $the_query = new WP_Query( array(
    'posts_per_page' => 3,
    )); 
  ?>
 <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

  <?php $titles[]=get_the_title(); ?>
  <?php $contents[]=get_the_content(); ?>
  <?php $links[]=get_the_permalink();?>

  <?php endwhile; ?>

现在在我想要的地方打印我的页面中的值

<?php echo $titles[0]; ?>
<?php echo $titles[1]; ?>
<?php echo $titles[2]; ?>

对于其他声明的数组也一样。 :)

相关问题