
以下是基础代码,根据自己需要进行修改!
<?php
$rand_posts = get_posts('numberposts=8&orderby=rand'); //循环随机显示文章数
foreach( $rand_posts as $post ) :
?>
<dl>
  <?php
    $litpic = get_post_meta($post->ID, 'litpic', true);
    if (empty ( $litpic )) { //没有图片的文章
      echo '';
    }
    else { //显示有图片的文章
      echo '<dt><a href="'.get_permalink().'" title="'.trim(strip_tags( $post->post_title )).'"><img src="'. $litpic .'"/></a></dt>';
    } ?>
      <dd class="title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></dd>
</dl>
<?php endforeach; ?>
wordpress如何获取get_post_meta自定义属性
标签: get_post_meta, wordpress调用文章
上面是“wordpress如何调用有图片的文章”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_4486.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

 wordpress技巧中如何实现分类法项目列表页标题