简体   繁体   English

在wordpress中显示已定义帖子的完整帖子(而非摘录)

[英]Show full post (not excerpt) for defined posts in wordpress

I'd like to have the possibility to define some posts in wordpress where the full post is shown and not an excerpt. 我想有可能在wordpress中定义一些显示完整帖子而不是摘录的帖子。

There are various solutions like: 有多种解决方案,例如:

  • Use a hidden html to declare this and code into the theme to either use the_content or the_excerpt 使用隐藏的html进行声明,并编码到主题中以使用the_content或the_excerpt
  • Hardcode into the theme (if postid == xx then the_content else the_excerpt) 硬编码到主题中(如果postid == xx,则the_content否则the_excerpt)
  • Use post meta data and add "if" into theme to check for them 使用发布元数据并在主题中添加“如果”以检查它们
  • Create a plugin which adds the functionality automatically and also a checkbox "Always show full" into the post-editor. 创建一个插件,该插件会自动添加功能,并在后编辑器中添加一个复选框“始终显示完整”。

The first one is easy but ugly, 2nd one should be doable with some googling but the 3rd one seems to be the most appealing to me but I have no idea how to achieve this. 第一个很简单但是很丑陋,第二个应该可以通过谷歌搜索来实现,但是第三个似乎对我来说最有吸引力,但是我不知道该如何实现。

Since usually in the template all i have is somewhere the_excerpt method from wordpress. 由于通常在模板中,我所拥有的只是来自wordpress的the_excerpt方法。 I therefore should somehow inject some code there and check if the checkbox for the current post is set and then just use the_content instead. 因此,我应该以某种方式在此处注入一些代码,并检查当前帖子的复选框是否已设置,然后仅使用the_content即可。 Is this possible at all or do I need to modify the theme anyway? 这有可能吗,还是我仍然需要修改主题?

Thanks for your inputs. 感谢您的投入。

I would use custom fields, it's more flexible, so you don't need to hard code the page ids. 我会使用自定义字段,它更灵活,因此您无需对页面ID进行硬编码。

<?php
$show_full_content = get_post_meta($post->ID, 'show_full_content', true);

if ($show_full_content == 'yes') {
    the_content();
} else {
    the_excerpt();
}
?>

You might be interested in ACF , it can make it more user friendly. 您可能对ACF感兴趣,它可以使其变得更加用户友好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM