admin管理员组文章数量:1313081
I am trying to make a page to be persistent as the home page for my custom theme. In which I can download from Github and setup the Wordpress and this page appears as the default one. I created a page within the theme as front-page.php
and added the following code within it:
<?php
/* Template Name: front-page */
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php
if ( have_posts() ) {
// Load posts loop.
while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/content/content' );
}
// Previous/next page navigation.
twentynineteen_the_posts_navigation();
} else {
// If no content, include the "No posts found" template.
get_template_part( 'template-parts/content/content', 'none' );
}
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php
get_footer();
?>
However, it just appears as normal template. The same as if I created a books.php
page and setup it as the template name as well. I know it can be done from setthings>reading but I just would like to set it as the default one.
I have also added the following code into the functions.php
to display the front-page.php
template as the default but it makes the homepage disappear.
/*
* Add custom template as default page
*/
add_filter( 'template_include', 'breed', 99 );
function breed( $template ) {
if ( is_singular( 'page' ) ) {
$default_template = locate_template( array( 'breed.php' ) );
if ( '' != $default_template ) {
return $default_template ;
}
}
return $template;
}
I am trying to make a page to be persistent as the home page for my custom theme. In which I can download from Github and setup the Wordpress and this page appears as the default one. I created a page within the theme as front-page.php
and added the following code within it:
<?php
/* Template Name: front-page */
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php
if ( have_posts() ) {
// Load posts loop.
while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/content/content' );
}
// Previous/next page navigation.
twentynineteen_the_posts_navigation();
} else {
// If no content, include the "No posts found" template.
get_template_part( 'template-parts/content/content', 'none' );
}
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php
get_footer();
?>
However, it just appears as normal template. The same as if I created a books.php
page and setup it as the template name as well. I know it can be done from setthings>reading but I just would like to set it as the default one.
I have also added the following code into the functions.php
to display the front-page.php
template as the default but it makes the homepage disappear.
/*
* Add custom template as default page
*/
add_filter( 'template_include', 'breed', 99 );
function breed( $template ) {
if ( is_singular( 'page' ) ) {
$default_template = locate_template( array( 'breed.php' ) );
if ( '' != $default_template ) {
return $default_template ;
}
}
return $template;
}
Share
Improve this question
asked Dec 13, 2020 at 18:50
Elias PradoElias Prado
1135 bronze badges
1
|
1 Answer
Reset to default 0this is done without any code, in the dashboard using the template presented or any other and has no need for the function added to functions.php. try this steps:
- Pages > add new: create new page with any name adding the title and publish;
- Pages > all pages > quick-edit(on the page created): on templates choose the page template of choice, for example "front-page" and update;
- Appearance > customize > homepage settings: on the " Your homepage displays" choose "a static page", on "home page" choose your page created that now displays your template and update.
this should set your home page.
本文标签: How to make a page as default page for a theme without a plugin
版权声明:本文标题:How to make a page as default page for a theme without a plugin? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741918873a2404891.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
front-page.php
template file, if it exists." - more details here. – Sally CJ Commented Dec 14, 2020 at 1:45