将类型索引发布为Wordpress首页

时间:2014-08-16 20:42:18

标签: wordpress

如何将帖子类型的索引页面作为Wordpress的首页提交?在设置中,Wordpress仅允许页面作为首页。

Example:
Post type: Book
Post type slug: books
Post type index: archieve-books.php

我需要mydomain.com/books作为mydomain.com的首页 感谢。

1 个答案:

答案 0 :(得分:0)

使用自定义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();
?>

您现在可以选择此页面作为静态首页。

相关问题