Show full post (not excerpt) for defined posts in

2019-08-18 05:39发布

I'd like to have the possibility to define some posts in wordpress where the full post is shown and not an excerpt.

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
  • Hardcode into the theme (if postid == xx then the_content else 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. 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. Is this possible at all or do I need to modify the theme anyway?

Thanks for your inputs.

标签: php wordpress
1条回答
我想做一个坏孩纸
2楼-- · 2019-08-18 06:19

I would use custom fields, it's more flexible, so you don't need to hard code the page ids.

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

查看更多
登录 后发表回答