简体   繁体   中英

Clone an entire page to custom index.php

I am building a custom index.php file in my child theme overriding the default theme index.php file which loads first when the theme is first installed.

Is there a way to clone an entire page to index.php file by page name or id or slug? I will build a page by adding a new page from dashboard and add elements there. Now, when I build the page, I also want the index.php file look the same. Hope I make sense.

I have created a custom template as the index.php file. But not sure about the cloning process. Any help will be appreciative.

thanks

You can get the code from page.php of your parent theme inside your index.php - in this file you'll have all that is needed to display a page. For example in WP default theme, this code from page.php will display the current page using content-page.php template :

while ( have_posts() ) : the_post();
    get_template_part( 'content', 'page' );
    endif;
endwhile;

Then, in WP settings, define your page as home page in Settings > Reading - it will tell wordpress to use that page for your index.php template.

I got it resolved this way.

<?php
            if ( have_posts() ) :
                while ( have_posts() ) : the_post();
                    $post_format = et_pb_post_format(); ?>
<?php
                    $page = get_page_by_title('Default Homepage'); 
$content = apply_filters('the_content', $page->post_content);
echo $content;
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM