here is my scenario: I got an index.php which loads every page I got one below the other. It's a one-pager in the end.
I found this snippet online and It helped me a lot by creating this.
<?php
$mypages = get_pages( array('child_of' => 1503, 'sort_column' => 'menu_order') );
foreach( $mypages as $page ) {
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( 'the_content', $content );
?>
<section>
<div class="headlines info-header"><img src="<?php echo get_template_directory_uri(); ?>/assets/images/arrow.png" alt="arrow"><?php echo $page->post_title; ?></div>
<div class="page-content"><?php echo $content; ?></div>
</section>
<?php
}
?>
It seems to work just fine. But now to the problem part of this. I want to display the posts also on this one page. My try was to create another page news
and place a widget on this page which shows the latests posts, filtered by category.
But now the page title won't show up anymore, all I got is the following
notice: NOTICE: TRYING TO GET PROPERTY 'POST_TITLE' OF NON-OBJECT IN
So I thought the problem might have to do with the little <?php echo $page->post_title; ?>
I already tried to just get the_title
but I ended up getting the same error.
I'm kinda new to Wordpress so I don't know how to deal with this. Is there another way to get the page title on my index.php?
Best, Dominik