WordPress display page contents and a loop?

I have a custom loop in a page template to display posts by category by give category and tag. It works, but above the loop I need to show the content of the page itself, i.e. the content that’s been entered into the WordPress Dashboard normally.

What do I add to my template to display this content?

Read More

I have tried:

 $id = $post->ID;
 get_page($id);
 // then my custom loop

Which does get the current page ID, but no content.

Related posts

Leave a Reply

3 comments

  1. In WordPress, calling

    <?php the_content(); ?>
    

    will pull in the content from the WYSIWYG editor on the page that is using that template as long as it is inside the loop.

    The most basic example of this might look like this:

    <?php while (have_posts()) : the_post();/* Start loop */ ?>
            <?php the_content(); ?>
    <?php endwhile; /* End loop */ ?>
    
    <!-- Enter your custom loop for displaying posts by category down here -->
    

    More info here: http://codex.wordpress.org/Function_Reference/the_content

  2. In my case, with a modern theme and using Gutenberg blocks, I had to apply filters to the content before the posts loop, as mentioned in this thread here: Proper way to get page content

    Following one of the examples, a simple working solution would be:

    <?php
        $id = 669; // page ID that has been assigned for posts
        $post = get_post($id);
        $content = apply_filters('the_content', $post->post_content);
        echo $content;
    ?>
    
    <!-- Enter your custom loop for displaying posts by category down here -->