文章描述:
wordpress指定栏目ID或者文章ID调用文章信息
栏目ID
<?php
$args=array(
\'cat\' => 1, // 分类ID
\'posts_per_page\' => 10, // 显示篇数
\'order\'=> \'DESC\'
);
query_posts($args);
if(have_posts()) : while (have_posts()) : the_post();
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), \'full\');//图片
?>
<li>
<div><img src=\"<?=$full_image_url[0];?>\"/> </div>
<h2><a href=\"<?php the_permalink(); ?>\"><?php the_title(); ?></a></h2>
<p>
<?php if (has_excerpt()) {
// echo $description = get_the_excerpt(); //文章编辑中的摘要
echo wp_trim_words( get_the_excerpt(),200);
}else {
echo mb_strimwidth(strip_tags(apply_filters(\'the_content\', $post->post_content)), 0, 170,\"……\"); //文章编辑中若无摘要,自定截取文章内容字数做为摘要
} ?>
<span><?php the_time(\'Y年m月d日\')?> </span></p>
</li>
<?php endwhile; endif; wp_reset_query(); ?>
文章ID
$post_id = 1; // 文章ID,可以在WP后台找到
echo get_post( $post_id )->post_title; // 输出文章的标题
echo get_permalink($post_id);//文章链接
THE END
请登录后查看评论内容