• I want to include one page in another. Actually, I’ve got a couple paragraphs of content that I want to include on multiple pages. It’s updated roughly monthly, so I want to be able to edit it only in one place and have it appear in others.

    I’ve got it working, but ONLY if the “Include this page in user menus” option is enabled in the page I want to include. I don’t want it in the menus, though. I want it to be publicly viewable, but basically hidden.

    First, I installed the Exec-PHP plugin so that I could put PHP code into a post. Then, I stole some code from the Function Reference/get_pages codex page, and modified it to include only the page I want. The code is:

    <?php
        $pages = get_pages('include=144');
        $count = 0;
        foreach($pages as $page)
        {
            $content = $page->post_content;
            if(!$content)
                continue;
            if($count >= 2)
                break;
            $count++;
            $content = apply_filters('the_content', $content);
        ?>
            <div class=\"entry\"><?php echo $content ?></div>
        <?php
        }
    ?>

    Now, I confess that I don’t understand this code in its entirety (I’m sure that a lot of it is unnecessary for a single-page usage, but until I get it working, I didn’t want to put too much effort into paring it down), but if I change it to “include=2” (the front page), it works just fine. I can change the number to any page that is on the “Pages” menu. I’ve got two pages not on the menu and one that’s saved as a private page, and none of them display. I’m not surprised the private page won’t display, but what do I have to do in order to get a public page that’s not on the menu to display?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to include one page in another (when not in menu)’ is closed to new replies.