您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
20. 获取文章各种数据的模板标签-下
发布时间:2023-03-12 20:53:13编辑:雪饮阅读()
基于上篇继续获取文章的各种数据,优先级仍然忽略,直接写在当前主题目录index.php中
<!--
虽然官方比较推荐下面这种方式,实际上据说下面这种方式也是依赖于post全局变量的
据说the_content比较推荐,get_the_content好像是没有处理对于安全方面有好处的一些逻辑吧。
又或者这里所有涉及有含前缀get的方法以the_xxx结尾的这种,都有the_content和get_the_content的的据说的说法吧
对于下面获取摘要的那两个方法,如果文章中只设置了正文,没有设置摘要,则好像默认抽取正文的部分做为摘要。
若没有正文,则这里正文不显示,摘要也不显示。
若没有正文,但设置了摘要,我这里没有测试。
-->
<?php if(have_posts()):?>
<?php while(have_posts()):the_post();?>
<div style="border:1px solid pink;">
<div style="display:flex;justify-content: center;">
<div style="border:1px solid red; width:90%;">
<p>作者名称 get_the_author:<?php echo get_the_author();?></p>
<p>作者名称 the_author:<?php the_author();?></p>
</div>
</div>
<div style="display:flex;justify-content: center;">
<div style="border:1px solid red; width:90%;">
<p>获取文章别名:<?php echo $post->post_name;?></p>
<p>获取文章别名(urldecode):<?php echo urldecode($post->post_name);?></p>
</div>
</div>
<div style="display:flex;justify-content: center;">
<div style="border:1px solid red; width:90%;">
<p>文章编号 the_ID:<?php the_ID();?></p>
<p>文章编号 get_the_ID:<?php echo get_the_ID();?></p>
</div>
</div>
<div style="display:flex;justify-content: center;">
<div style="border:1px solid red; width:90%;">
<p>文章的网址 get_the_permalink:<?php echo get_the_permalink();?></p>
<p>文章的网址 the_permalink:<?php the_permalink();?></p>
</div>
</div>
<div style="display:flex;justify-content: center;">
<div style="border:1px solid red; width:90%;">
<p>发布时间 the_time:<?php the_time();?></p>
<p>发布时间 the_time(param):<?php the_time('Y-m-d H:i:s');?></p>
<p>发布时间 get_the_time:<?php echo get_the_time();?></p>
</div>
</div>
<div style="display:flex;justify-content: center;">
<div style="border:1px solid red; width:90%;">
<p>作者归档页的超链接 get_the_author_posts_link:<?php echo get_the_author_posts_link();?></p>
<p>评论数量 get_comments_number:<?php echo get_comments_number();?></p>
</div>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<p>对不起,暂时没有任何内容!</p>
<?php endif;?>
这里值得说明的是这个发布时间除了param这种调用以外,其它的调用方式的显示格式好像是受限于wordpress后台设置里面的常规里面的日期格式和时间格式。
关键字词:
相关文章
-
无相关信息