admin管理员组文章数量:1393058
I created a single page WordPress theme to learn the process of creating a theme, and it all works great and all, but it's done in a very hack-ish way where if I wanted to distribute this, I'd have people wondering how the hell it works.
In short, you create pages like you would any other theme, and then you add them to your main menu. My code then reads the menu contents and loads the page content in the order the pages are on the menu. (See code below)
Obviously this is not how it should be done. What I'd like to know is how am I supposed to do this? I've yet to find a good guide for single page themes and how they're supposed to work. Any help would be greatly appreciated.
And now my entire index.php
file:
<?php
/**
* @author Spedwards
* Date: 2020-01-20
*/
get_header();
$menu_slug = 'header-menu';
$locations = get_nav_menu_locations();
if (isset($locations[$menu_slug])) {
$menu = get_term($locations[$menu_slug]);
$menu_items = wp_get_nav_menu_items($menu->term_id);
if ($menu_items) {
foreach ($menu_items as $item) {
$page = get_page_by_title($item->title);
?>
<section class="section-page" id="<?= $page->post_title ?>">
<div class="container">
<h2 class="page-section-heading text-center text-uppercase mb-0"><?= $page->post_title ?></h2>
<div class="divider">
<div class="divider-line"></div>
<div class="divider-icon">
<div class="fas fa-crown"></div>
</div>
<div class="divider-line"></div>
</div>
<?= $page->post_content ?>
</div>
</section>
<?php
}
}
}
get_footer();
Live example
本文标签: Creating a Single Page Theme correctly
版权声明:本文标题:Creating a Single Page Theme correctly 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744772882a2624447.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论