你可以像贝娄那样做
// register shortcode
add_shortcode(\'last-modified\', \'last_mofied_shortcode_callback\');
function last_mofied_shortcode_callback() {
$output = \'<ol class="list-numbered">\';
$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();
$output .= \'<li><a href="\'.get_the_permalink().\'" rel="bookmark" title="\'.get_the_title().\'">\'.get_the_title();
$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 ) {
$output .= wp_get_attachment_image($thumb_id, $size);
}
$output .= \'</a></li>\';
endwhile;
wp_reset_postdata();
endif;
return $output;
}
现在你可以使用
[last-modified]
在内容中的任意位置进行快捷编码。如果您想在php文件中使用,那么只需像这样使用它
echo do_shortcode(\'[last-modified]\');
了解更多信息add_shortcode()
here