dongpo1203 2014-08-08 14:15
浏览 71
已采纳

get_template_part和get_footer的单页wordpress问题

What I'm trying to do is convert my one page design in wordpress and i thought it would be nice to be able to edit, add and modify different part of the page in seperated pages. The one page website will be ordered by a menu (with id main).

Following the wp-codex i used get_template_part, it should work properly because it should:

Load a template part into a template (other than header, sidebar, footer)

get_header gets skipped but get_footer gets excecuted and the site is rendered incorrectly.


front-page.php

$pages = wp_get_nav_menu_items('main');
global $post;
foreach ($pages as $post) {
    $post = get_post($post->object_id);
    if($post->post_type != "page") continue;
    setup_postdata( $post );
    $postName = (locate_template('page-' . $post->post_name . '.php') == '') ? null : $post->post_name;
    get_template_part('page', $postName);
}
wp_reset_postdata();

Is this a bug? Or did I do something wrong? What is the best way to accomplish this?

  • 写回答

4条回答 默认 最新

  • douji5329 2014-12-18 11:47
    关注

    I ended up copying the default page.php template as page-page.php and loaded it like this:

    $postName = (locate_template('page-' . $post->post_name . '.php') == '') ? 'page' : $post->post_name;
    

    Then in page.php just loaded page-page.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)