WordPress指定ID调用文章

文章描述:

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
版权声明 1、本网站名称:AOPK资源网
2、本站永久网址:https://www.aopk.cn
3、本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。

点赞6赞赏 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容