如何将帖子类型的首页作为Wordpress的首页提交?在设置中,Wordpress只允许页面作为首页。
Example:
Post type: Book
Post type slug: books
Post type index: archieve-books.php我需要mydomain.com /book被称为mydomain.com的首页,谢谢。
发布于 2014-08-17 15:58:51
使用自定义的page.php模板可以很容易地完成这一点。缺省情况下,不能将归档页面设置为首页,只能设置页面模板
有关参考信息,请参阅'Creating a Static Front Page'
要创建自定义首页,请复制您的page.php模板并将其重命名为front-page.php,然后在页面循环之后添加一个自定义查询以调用您的自定义帖子类型
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$args = array(
'post_type' => 'books',
'posts_per_page' => 5,
'paged' => $paged
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>你现在可以选择这个页面作为你的静态首页。
https://stackoverflow.com/questions/25343796
复制相似问题