如何在WordPress中启用图片库

时间:2019-06-12 18:47:27

标签: php html css wordpress

我正在尝试使图像功能显示在帖子的画廊中。

我试图通过上传图片,挑选我需要的图片并将其放入帖子中来以一种“正常”的方式在wordpress中建立一个画廊。

$post_id = 83;
$queried_post = get_post($post_id);
$title = $queried_post->post_title; ?>
<div id="gallery" class="section-top">
    <h1 class="section-heading"> <?php echo $title; ?></h1>
    <p class="center-find"><?php echo $queried_post->post_content;?></p>
</div>

我需要能够在网站上显示画廊。当我使用已检查的随机图片库中的简码时,我可以看到帖子中的图像,但是当我在front-page.php上进入网站时,得到的只是显示的实际简码而没有图像。

如果我以“查看帖子”的形式打开该帖子,则会显示图库,因此我想我的代码中缺少某些内容以使图像显示在首页上。

如果我直接在front-page.php中使用短代码,我也会得到图库,但是我的用户无法像他们想要的那样制作图库,而必须手动编辑模板文件自己,他们对编码一无所知。

1 个答案:

答案 0 :(得分:0)

如果您希望帖子内容通过简码,则应对其应用过滤器。您可能还想使用get_the_title代替post对象。

$post_id = 83;
$queried_post = get_post($post_id);
$content = apply_filters( 'the_content', $queried_post->post_content );
$title = get_the_title($post_id);
 <div id="gallery" class="section-top">
   <h1 class="section-heading"> <?php echo $title; ?></h1>
   <p class="center-find"><?php echo $content; ?></p>
 </div>