微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WordPress |如何围绕regulr HTML在POST的开头和结尾放置内容?

如何解决WordPress |如何围绕regulr HTML在POST的开头和结尾放置内容?

我有一个 wordpress 网站,我需要以某种方式将可更新的内容放在围绕常规 HTML 的 POST 中,该 HTML 是半自动半静态的。 这是代码

<img src="https://website.xyz/img.jpg" class="fullimgfirst" alt="">
<img src="https://website.xyz/img3.jpg" class="leftimg" alt="">
<img src="https://website.xyz/img4.jpg" class="rightimg" alt="">
<img src="https://website.xyz/img5.jpg" class="fullimg" alt="">

<div class="firstfull">
  <div class="firstleft">
    <p1>branding + Digital</p1>
  </div>
  <div class="firstright">
    <h1>Summit</h1>
  </div>
</div>
<div class="secondfull">
  <h2>Project overview</h2>
  <p2>The project description.</p2>
</div>

<img src="https://website.xyz/img2.jpg" class="bigimg" alt="">
<img src="https://website.xyz/img3.jpg" class="leftimg" alt="">
<img src="https://website.xyz/img4.jpg" class="rightimg" alt="">
<img src="https://website.xyz/img10.jpg" class="fullimglast" alt="">

用户只需更新所有图像和 P2。但是正如您所看到的,第一行和最后一行都有图像。如何在 wordpress 中做到这一点,让这部分保持静态:

<div class="firstfull">
  <div class="firstleft">
    <p1>branding + Digital</p1>
  </div>
  <div class="firstright">
    <h1>Summit</h1>
  </div>
</div>
<div class="secondfull">
  <h2>Project overview</h2>

每个帖子的图片和 P2 可上传/更新吗?

非常感谢您。

解决方法

您可以使用 ACF 插件。

为此,您必须为顶部和底部图像创建两个 ACF 中继器字段。并根据您的结构在模板中调用 ACF 字段。

P2 将来自管理页面 editor()

你可以这样写代码:

<?php if( have_rows('top_content_images') ): ?>
    <?php while( have_rows('top_content_images') ): the_row(); 
        $top_image = get_sub_field('content_image');
    ?>
        <?php echo wp_get_attachment_image( $top_image,'full' ); ?>
    <?php endwhile; ?>
<?php endif; ?>

<div class="firstfull">
    <div class="firstleft">
        <p1>Branding + Digital</p1>
    </div>
    <div class="firstright">
        <h1>Summit</h1>
    </div>
</div>
<div class="secondfull">
    <h2>Project overview</h2>
    <?php the_content();?>
</div>

<?php if( have_rows('bottom_content_images') ): ?>
    <?php while( have_rows('bottom_content_images') ): the_row(); 
        $bottom_image = get_sub_field('content_image');
    ?>
        <?php echo wp_get_attachment_image( $bottom_image,'full' ); ?>
    <?php endwhile; ?>
<?php endif; ?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。