2016-09-30 112 views
0

希望我的描述能够清楚!定义WP自定义帖子类型区域

我基本上正在尝试创建一个区域来显示投资组合工作。我已经在Wordpress中创建了一个自定义的帖子类型,并且希望将其带到front-page.php。我指定了要显示作品的区域(see image)。 深灰色的地方是我想放置投资组合物品的地方。每个灰色区域应显示1种组合项目

我使用这个脚本在自定义类型后拉:

<?php 
$args = array('post_type' => 'Portfolio', 'posts_per_page' => 4); 
    $loop = new WP_Query($args); 
     while ($loop->have_posts()) : $loop->the_post(); 
echo '<div class="home-recent-thumb">'; the_post_thumbnail(); echo '</div>'; 
echo '<div class="home-recent-title">'; the_title(); echo '</div>'; 
echo '<div class="home-recent-copy">'; the_excerpt(); echo '</div>'; 
endwhile; 
?> 

如何指定在PHP领域,使其显示里面4个员额正确的元素?

回答

0

由于您的布局不一定有利于传统的“循环”功能 - 意思是说,您不会将结果放在一起 - 而且您还没有提到任何外部库(如砌体或同位素) - 我只是针对四个方格中的每一个进行个别查询。

对于第一个自定义后类型方 - 它想:

$query = new WP_Query('post_type' => 'Portfolio', 'posts_per_page' => 1); 

而第二个(到第n)看起来像:

$query = new WP_Query('post_type' => 'Portfolio', 'posts_per_page' => 1, 'offset=1'); 

如果您抵消不断提高。在我看来,这继续保持动态,并且对于四个帖子来说足够简单。除此之外,您还可以跳入其他方块的其他逻辑。

0
<?php 
$portfolioPosts = get_posts([ 
    'post_type' => 'Portfolio', 
    'posts_per_page' => 4 
]); 
//first section 
?> 
<div class="home-recent-thumb"><?php the_post_thumbnail($portfolioPosts[0]->ID); ?></div> 
<div class="home-recent-title"><?php echo $portfolioPosts[0]->post_title ?></div> 
<div class="home-recent-copy"><?php echo $portfolioPosts[0]->post_excerpt; ?></div> 
<?php 
//later in code 
//second section 
?> 
<div class="home-recent-thumb"><?php the_post_thumbnail($portfolioPosts[1]->ID); ?></div> 
<div class="home-recent-title"><?php echo $portfolioPosts[1]->post_title ?></div> 
<div class="home-recent-copy"><?php echo $portfolioPosts[1]->post_excerpt; ?></div> 
//et cetera 
相关问题