我目前正在处理我的第一个WordPress主题,并且想要在index.php上创建“突出显示的帖子”部分。这里有很多脚本,但似乎都在整个index.php上应用永久过滤器。这是有问题的,因为我想在我的index.php下面显示整个帖子。有没有办法将这个特殊的过滤器只适用于这个部分,而不是整个index.php?仅在首页显示WordPress帖子的第一句话作为“突出显示的帖子”部分
-1
A
回答
1
如果你可以给我们更多的信息什么决定了这些“突出显示”的帖子,我们可能会更具体地解决这个问题。
但在平均时间,我会想这是两款最新的帖子,这意味着你可以有两个查询在index.php
第一个将是“突出”的:
<?php
$args = array('numberposts' => 2);
$lastposts = get_posts($args);
foreach($lastposts as $post) : setup_postdata($post);
?>
<h2 class="news"><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<?php endforeach; ?>
这会给你在这个查询中的文章的摘录。
你可以做的,然后是限制摘录自己喜欢的任意长度和添加,如果你想:)
function newExcerpt($more) {
global $post;
return '... <a href="'. get_permalink($post->ID) . '">Read more</a>';
}
add_filter('excerpt_more', 'newExcerptReadMore');
function customExcerptLength($length) {
return 20;
}
add_filter('excerpt_length', 'customExcerptLength', 999);
读更多链接的其他职位,你可以做另一个查询,但不使用前两个这样的帖子:
$count = 0;
$lastposts = get_posts();
foreach($lastposts as $post) : setup_postdata($post);
if($count > 1)
?>
<h2 class="news"><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
$counter++;
<?php endforeach; ?>
这将只是循环通过帖子和跳过前两个帖子。 如果您有其他一些术语或类别或其他决定突出显示的帖子的内容,那么您可以使用它并将其作为参数传递给get_posts($ args)。
相关问题
- 1. 在首页显示帖子
- 2. 从帖子到帖子在Wordpress循环页面显示所有帖子显示
- 3. 仅显示主页上帖子的第一句
- 4. 在wordpress的父母帖子页面上显示子帖子
- 5. WordPress - 每一页的帖子都显示相同的帖子
- 6. WordPress的显示帖子仅修改
- 7. WordPress的循环不仅显示帖子
- 8. 在Wordpress帖子页面显示一个帖子类别
- 9. WordPress的显示帖子
- 10. 显示帖子 - WordPress的
- 11. WordPress的帖子不显示
- 12. 在wordpress中显示第五个帖子
- 13. WordPress的 - 帖子页面显示相同的5帖子
- 14. WordPress的显示全部帖子
- 15. WordPress的显示Catgeory帖子上页
- 16. 在Jekyll中突出显示帖子
- 17. 在wordpress的首页显示特定的帖子标题
- 18. 在两页上显示Wordpress帖子
- 19. WordPress - 在页面中显示帖子
- 20. 在多个页面显示Wordpress帖子
- 21. Wordpress在第一页显示某个类别的帖子
- 22. WordPress的帖子没有显示出来
- 23. Wordpress,第2页显示与第1页相同的帖子
- 24. 如何使用分页显示给定帖子的子帖子?
- 25. JSF字段突出显示ajax帖子?
- 26. 显示一位作者的帖子,仅从当前类别(wordpress)
- 27. WordPress,帖子正在显示在首页(index.php)?
- 28. WordPress的 - 静态首页应该显示最新帖子
- 29. 显示较早的帖子第一
- 30. 在Wordpress中显示类别的帖子?
我建议你为此使用JavaScript/jQuery – tamal3053