wp文章调用php接口,wordpress文章的各种调用

本文详细介绍了如何在WordPress中调用文章的各种元素,包括标题、内容、摘要、作者信息、发布时间、Gravatar头像、特色图片以及固定链接。此外,还展示了如何自定义特色图像的大小,并提供了一种获取文章第一幅图片的方法。对于开发者来说,这些代码片段对于构建WordPress主题非常有用。
摘要由CSDN通过智能技术生成

调用文章标题:<?php the_title(); ?>

调用文章内容:<?php the_content(); ?>

调用文章摘要:<?php the_excerpt(); ?>

调用作者姓名:<?php the_author(); ?>

调用文章发布时间:<?php the_time(); ?>

调用作者的Gravatar头像:<?php echo get_avatar( get_the_author_email(), 36 ); ?>

调用特色图片:<?php the_post_thumbnail();?>

调用固定链接:<?php the_permalink(); ?>

the_post_thumbnail(); // 默认显示缩略图

the_post_thumbnail(‘thumbnail’); // 显示缩略图

the_post_thumbnail(‘medium’); // 显示中等尺寸

the_post_thumbnail(‘large’); // 显示大尺寸

the_post_thumbnail( array(200,200) ); // 自定义尺寸

对特色图像大小进行设置

if ( function_exists( 'add_theme_support' ) ) {

add_theme_support( 'post-thumbnails' );

}

if(function_exists('set_post_thumbnail_size')){

set_post_thumbnail_size(231,160,true);

}

if ( function_exists( 'add_image_size' ) ) {

add_image_size( 'big', 432, 234, true );

add_image_size( 'car', 179, 109, true );

}

调用文章的第一幅图

在functions.php中加入代码:

function catch_that_image() {

global $post, $posts;

$first_img = '';

ob_start();

ob_end_clean();

$output = preg_match_all('//i',

math?formula=post-%3Epost_content%2Cmatches);

$first_img = $matches [1] [0];

if(empty($first_img)){ //Defines a default image

$first_img = "/images/default.jpg";

}

return $first_img;

}

?>

在要调用图片的地方加入代码:

<?php%20echo%20catch_that_image()%20?>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值