2017-04-27 59 views

回答

1

是的,你可以通过传递后IDS与阵列获得头版具体职位包括参数这样的事情,

<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> 

希望这个作品。

+0

谢谢,这为我工作。 –

+0

,但你能告诉我如何得到前3或2个职位的ID,而不分配他们在array.like自动它得到顶级2或3职位的ID。 –

+0

如果您想动态显示帖子而不是静态ID,那么您不需要在查询中添加'include'参数。只需将其删除并替换为''posts_per_page'=> 3,'。它返回你前3名最新职位。 –

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]; ?> 

而且同其他声明数组。 :)

相关问题