我正在搜索在函数中创建一个短代码。php子主题,用缩略图显示上次更新的帖子。我有以下代码可用于页面模板:
<ol class="list-numbered">
<?php
// Show recently modified posts
$recently_updated_posts = new WP_Query( array(
\'post_type\' => \'post\',
\'posts_per_page\' => \'13\',
\'orderby\' => \'modified\',
\'no_found_rows\' => \'true\' // speed up query when we don\'t need pagination
) );
if ( $recently_updated_posts->have_posts() ) :
while( $recently_updated_posts->have_posts() ) : $recently_updated_posts->the_post(); ?>
<li><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?>
<?php
$size = \'thumbnail\';
$attachments = get_children( array(
\'post_parent\' => get_the_ID(),
\'post_status\' => \'inherit\',
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
\'order\' => \'ASC\',
\'orderby\' => \'menu_order ID\',
\'numberposts\' => 1)
);
foreach ( $attachments as $thumb_id => $attachment ) {
echo wp_get_attachment_image($thumb_id, $size);
}
?>
</a></li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</ol>
但我会在函数中插入。php文件,并调用短代码。你有什么想法吗?提前谢谢。