我遇到了一个奇怪的问题。我创建了一个自定义主页模板,将两个不同类别的最新5篇文章拉到布局中(请参阅"学习"answers"播放"列)
http://sensoryrevolution.com.s177767.gridserver.com/
我通过从这个网站复制粘贴的自定义查询拉入了4个字段:
- 张贴缩略图
- Permalink
- 职务
- 摘录
只有摘录是错误的。它显示了上面博客文章的摘录
这是我用来插入的代码。奇怪的是,它一直在工作,现在却坏了。我已经放弃了其他一些自定义代码,这些代码限制了摘录中的字符数,所以这纯粹是the_excerpt()
发挥其魔力。
<?php $posts = get_posts('category=213&orderby=desc&numberposts=5'); foreach($posts as $post) { ?>
<h4><a href="<?php the_permalink() ?>" target="_parent"><?php the_title(); ?></a></h4>
<a href="<?php the_permalink() ?>" target="_parent"><?php the_post_thumbnail('blog-large'); ?></a>
<p><?php the_excerpt() ?><?php // echo excerpt(22) ?></p>
<?php } ?>
这简直把我逼疯了!有人有什么想法吗?
文章摘录来自wordpress中的摘录字段。默认情况下,摘录字段不会显示在管理后台的wordpress单个帖子/页面上。您可以通过单击"添加新"帖子/页面(或自定义页面)右上角的"屏幕选项"来添加它。然后,您可以输入任何您想要的文本作为摘录。
正如你从你的var_dump中看到的,它说帖子中没有摘录:
CCD_ 2。
如前所述,the_excerpt()
不在主要内容主体中查找摘录。如果你不想在后端添加摘录字段,你可以这样做:
$content = get_the_content(); echo substr($content, 0, 20);
这将输出字符串的前20个字符(这是页面/帖子/自定义帖子的内容)。显然,你也可以做40
或类似的事情,以适当地输出你认为是仪式量的东西。
编码快乐!