我将其作为一个函数进行了测试。您可以将其放置在页脚或函数中。php主题文件,并在主题页脚部分调用它。有关所用函数的链接,请参见注释。
function wpse_101774_footer() {
// Start this part of footer on new line.
echo "\\n";
foreach ( array( 14, 19 ) as $page_id ) {
// Start .footercat div.
echo "<div class=\'footercat\'>\\n";
// Print the Parent post anchor markup.
// See: http://codex.wordpress.org/Function_Reference/get_permalink
// See: http://codex.wordpress.org/Function_Reference/get_the_title
printf( \'<h2><a href="%s">%s</a></h2>\', get_permalink( $page_id ), get_the_title( $page_id ) );
echo \'<ul>\';
// List the child pages.
// See: http://codex.wordpress.org/Function_Reference/wp_list_pages
wp_list_pages( array(
\'depth\' => 1,
\'child_of\' => $page_id,
\'post_type\' => \'page\',
\'post_status\' => \'publish\',
\'title_li\' => \'\',
) );
echo \'</ul>\';
// End .footercat div.
echo "\\n</div><!-- end .footercat -->\\n";
}
$blog_post_id = 3081;
// Print the Blog page anchor markup.
// See: http://codex.wordpress.org/Function_Reference/get_permalink
// See: http://codex.wordpress.org/Function_Reference/get_the_title
printf( \'<h2><a href="%s">%s</a></h2>\', get_permalink( $blog_post_id ), get_the_title( $blog_post_id ) );
// Start .footercat div.
echo "<div class=\'footercat\'>\\n";
echo \'<ul>\';
// Add comma separated list of ctegory IDs in place of "1" (For example, 1, 45, 6 ).
foreach ( array( 1 ) as $category_id ) {
// Get the category object for this category ID.
// See: http://codex.wordpress.org/Function_Reference/get_category
$category = get_category( $category_id );
// Get this category\'s posts.
// See: http://codex.wordpress.org/Function_Reference/get_posts
$posts = get_posts( array(
\'posts_per_page\' => 5,
\'category\' => $category_id,
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'suppress_filters\' => true
) );
$post_anchors = \'\';
if ( $posts ) {
$post_anchors = \'<ul>\';
foreach ( $posts as $post ) {
// Print this category\'s posts.
// See: http://codex.wordpress.org/Function_Reference/get_permalink
// See: http://codex.wordpress.org/Function_Reference/get_the_title
$post_anchors .= sprintf(
\'<li><a href="%s">%s</a></li>\',
get_permalink( $post->ID ),
get_the_title( $post->ID )
);
}
$post_anchors .= \'</ul>\';
}
// Print this category\'s anchor and post anchors, if any.
// See: http://codex.wordpress.org/Function_Reference/get_category_link
printf( \'<li><a href="%s">%s</a>%s</li>\', get_category_link( $category_id ), $category->name, $post_anchors );
}
echo \'</ul>\';
// End .footercat div.
echo "\\n</div><!-- end .footercat -->\\n";
}