I've created a custom theme, and I want to display a custom theme page that I created, whose file name is
page-about.php
.The only way that I know that it's possible to display custom theme pages in WordPress is to make their files templates, and then create a page via the
WP-Admin
whose template is of the desired file, so what I did, is added at the top ofpage-about.php
the comment in PHP:Template Name: About Me
.I, then, created a page via the
WP-Admin
calledpage-about
.The contents of the pages are printed via the following loop in my
functions.php
page:function display_all_pages() { $pages = get_pages(); foreach ($pages as $page) { $id = $page->post_title; $id = strtolower(str_replace(' ', '_', $id)); $class = "page"; $content = $page->post_content; echo ('<div ' . 'id="' . $id . '"' . 'class="' . $class . '">' . $content . '</div>'); } }
And this is the content of the
page-about.php
file:<?php /* * Template Name: About Me */ get_header(); ?> <?php echo "hello"; ?> <body <?php body_class(); ?>> <p> This is the About Me page. </p> </body>
I've checked by doing
var_dump
on$page
inside the loop, and saw thatpost-content
ofabout-page
is empty. The problem is that my loop doesn't print anything. It makes sense to me that thepost-content
is empty, because the I inserted no content topage-about
onWP-Admin
. But, on the other hand, I saw in an old video, from about here that I did something that should work.
Why doesn't what I do work, and what do I need to do to make it work? Thanks in advance.
display_all_pages
function in your template? Because, from your code, it doesn't appear that you are. – socki03 Jun 7 '17 at 16:36display_all_pages
runs, and displays successfully all the other pages that are were created. Just a side note: I don't have apage.php
file. Is this relevant? My website is a one-pager, sodisplay_all_pages
is called only in myindex.php
file. – Gal Grünfeld Jun 7 '17 at 16:57