zl程序教程

您现在的位置是:首页 >  其他

当前栏目

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

WordPress 实现 使用 推荐 自定义 文章 ---
2023-06-13 09:12:33 时间

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

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

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

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

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

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

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