我想在首页以以下格式显示类别帖子:
健康:第1岗第2岗第3岗
体能:第1岗第2岗第3岗
美丽第一岗第二岗第三岗
网站示例:beautyhealthtips。在里面
有人帮我吗?
谢谢
我想在首页以以下格式显示类别帖子:
健康:第1岗第2岗第3岗
体能:第1岗第2岗第3岗
美丽第一岗第二岗第三岗
网站示例:beautyhealthtips。在里面
有人帮我吗?
谢谢
function add_excluded_post_ids( $exclude_post_ids, $posts ) {
foreach( $posts as $post ) {
array_push( $exclude_post_ids, $post->ID );
}
return $exclude_post_ids;
}
$exclude_post_ids = array();
$latest_posts = get_posts( array(
\'numberposts\' => 3
) );
$exclude_post_ids = add_excluded_post_ids( $exclude_post_ids, $latest_posts );
$health_posts = get_posts( array(
\'numberposts\' => 3,
\'category\' => get_category_by_slug( \'health\' )->term_id, // Change accordingly
\'exclude\' => $exclude_post_ids
) );
$exclude_post_ids = add_excluded_post_ids( $exclude_post_ids, $latest_posts );
$fitness_posts = get_posts( array(
\'numberposts\' => 3,
\'category\' => get_category_by_slug( \'fitness\' )->term_id, // Change accordingly
\'exclude\' => $exclude_post_ids
) );
$exclude_post_ids = add_excluded_post_ids( $exclude_post_ids, $fitness_posts );
$beauty_posts = get_posts( array(
\'numberposts\' => 3,
\'category\' => get_category_by_slug( \'beauty\' )->term_id, // Change accordingly
\'exclude\' => $exclude_post_ids
) );
现在您有$latest\\u posts、$health\\u posts、$fitness\\u posts和$beauty\\u posts。它们中的每一个都存储一组3篇文章,您可以使用这些文章生成HTML。您可以使用一个输出整个HTML的短代码,然后将此短代码插入到“页面”中,最后将主页设置为“静态页面”。注意$health\\u posts、fitness\\u posts和$beauty\\u posts将分别存储属于这些类别的最新帖子。如果您希望通过其他参数(如视图数量)或随机检索这些帖子,则必须使用WP_Query
而不是get_posts()
.
如何阻止“正在使用”消息在中间歇性出现phpMyAdmin wp_posts 桌子我之前没有警告和错误消息,但当它发生在我的wp_posts 表中,我的所有内容都被阻止加载。修复表总是会修复它,但在再次发生之前,这是一个临时修复。