xxx/?page_id=5
想在首页调用以上页面的内容怎么做呢?
完整:
<?php //查询 $my_query = new WP_Query( ‘page_id=5‘ ); if($my_query->have_posts()) : while($my_query->have_posts()) : $my_query->the_post(); ?> //............输出 //............结束 <?php endwhile; endif; ?>
============================选择调用内容============================
调用缩略图:
<?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail( ‘thumbnail‘ ); ?> <?php else: ?> //显示默认图片 <?php endif; ?>
调用内容(带截取):
<?php $content = get_the_content(); $trimmed_content = wp_trim_words( $content, 40, ‘<a href="‘. get_permalink() .‘"> ...Read More</a>‘ ); echo $trimmed_content; ?>
调用标题(带截取):
<?php $title = get_the_title(); $trimmed_title = wp_trim_words( $title, 20, ‘...‘ ); echo $trimmed_title; ?>
时间: 2024-10-29 19:08:02