简体   繁体   English

将整个页面克隆到自定义index.php

[英]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. 我正在子主题中构建自定义index.php文件,该主题将覆盖默认主题index.php文件,该主题将在首次安装主题时首先加载。

Is there a way to clone an entire page to index.php file by page name or id or slug? 有没有一种方法可以通过页面名称或id或slug将整个页面克隆到index.php文件? 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. 现在,当我构建页面时,我还希望index.php文件看起来相同。 Hope I make sense. 希望我有道理。

I have created a custom template as the index.php file. 我已经创建了一个自定义模板作为index.php文件。 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. 您可以从index.php内父主题的page.php中获取代码-在此文件中,您将拥有显示页面所需的全部内容。 For example in WP default theme, this code from page.php will display the current page using content-page.php template : 例如,在WP默认主题中, page.php中的此代码将使用content-page.php模板显示当前页面:

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. 然后,在WP设置中,在“设置”>“阅读”中将您的页面定义为主页-它会告诉wordpress使用该页面作为index.php模板。

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;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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