前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >wordpress 自定义字段使用---实现推荐文章

wordpress 自定义字段使用---实现推荐文章

作者头像
切图仔
发布2022-09-14 15:42:27
8850
发布2022-09-14 15:42:27
举报
文章被收录于专栏:生如夏花绚烂

1.下载-安装-启用 Advanced Custom Fields 插件

2.在左侧功能区->字段->新键字段组

3.在字段组下面键入 自定义字段及其相关设置 ->保存->发布

4.在文章编辑功能区 ->更多->勾选自定义字段

5.在文章编辑区 即可键入该文章的自定义字段值

案例--首页展示推荐文章

代码语言:javascript
复制
<div class='zz-con'>
    <div class='row'>
        <?php if(have_posts()): ?>
            <?php while(have_posts()): the_post();?>
            //判断是否是推荐文章
            <?php if(get_post_meta($post->ID,'tj',true)) :?>
        <div class='col-md-4 col-sm-6'>
            <div class="card " style="width: 18rem;height: 18rem; ">
                <div class='card-img'>
                        <img src="static/picture/u=3188343412,147869045&amp;fm=26&amp;gp=0.jpg" class="card-img-top" alt="...">
                </div>
                <div class="card-body">
                <strong class='card-title text-truncate'><?php the_title();?></strong>
                <p class="card-text overflow-hidden" style='height:6rem'>
                    //文章摘要
                    <?php the_excerpt();?>
                    </p>
                   //文章链接
                    <a href="<?php the_permalink()?>" class="text-success mt-2 d-block">+阅读原文</a>
                </div>
            </div>
        </div>
            <?php endif;?>
        <?php endwhile;?>
        <?php endif;?>

    </div>
</div>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档