繁体   English   中英

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

[英]Clone an entire page to custom index.php

我正在子主题中构建自定义index.php文件,该主题将覆盖默认主题index.php文件,该主题将在首次安装主题时首先加载。

有没有一种方法可以通过页面名称或id或slug将整个页面克隆到index.php文件? 我将通过从仪表板添加新页面并在其中添加元素来构建页面。 现在,当我构建页面时,我还希望index.php文件看起来相同。 希望我有道理。

我已经创建了一个自定义模板作为index.php文件。 但是不确定克隆过程。 任何帮助将是感激的。

谢谢

您可以从index.php内父主题的page.php中获取代码-在此文件中,您将拥有显示页面所需的全部内容。 例如,在WP默认主题中, page.php中的此代码将使用content-page.php模板显示当前页面:

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

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

我这样解决了。

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