如何在每个 Wordpress post 的侧边栏中添加自定义内容?

How to add custom content in sidebar of each Wordpress post?

我想整合特定的文本(文本、链接、图像)参考我博客的特定句子post。

是否可以使用代码或使用插件来实现?

我给你发一张草图: This is the sketch

这是常见的需求,并且经常在 WordPress 中谈论它。有像 Aside Widget、Custom Sidebars 这样的 WP 插件可以满足普通需求。但是如果你需要太多自定义的东西,比如我网站的 "About this Article" 侧边栏小部件 - https://thecustomizewindows.com/2016/09/limitations-of-openvz-virtualization-to-guest-cloud-server-vps/ 那么最好使用 Otto 的这个插件在文本小部件中使用 PHP - https://wordpress.org/plugins/php-code-widget/ 并使用 PHP。在我的例子中,剩下的是侧边栏上的 PHP 代码(我也可以使用简码):

    <?php if(is_single()) : ?>
    <h3>About This Article</h3>
    <strong>Title:</strong> <?php echo get_the_title(); ?><br />
    Published on: <?php the_time('Y-m-d') ?>
    <br />
    ...
    // rest of the code
    <?php endif; ?>

显然你可以用 WordPress 函数调用 post 图片缩略图。

如果你需要特定的文本,你可以考虑结合 Pull Quote Plugin 或 Aside Widget 来标记特定的 like 并用 PHP 回显。

作为其他选项——您可以使用CSS3自动select第一行、第一段、第二句。您可以使用 Javascript 进行条件标记。

我看到的最佳定制是在 BMJ 的侧边栏上。他们使用 Drupal,而不是 WordPress。 BMJ 有漂亮的侧边栏 --(例如)- http://www.bmj.com/content/355/bmj.i4924 Drupal has description of the work - https://www.drupal.org/node/1557636 可悲的是我对 Drupal 缺乏了解。我在出于学术目的使用 WordPress 的背后做了很多尝试。