WordPress.org

Ready to get started?Download WordPress

Forums

"includes" in WordPress pages (2 posts)

  1. MacneticM
    Member
    Posted 4 years ago #

    In traditional websites, I like and, in a variety of different ways, frequently use server side includes. I'm currently in the process of converting one of these sites to a WordPress site and I'm now looking for a way to accomplish the same thing(s) within the WordPress system. It's very likely that what I'm trying to accomplich is already possible using standard WordPress features (or perhaps a plug-in may exist); I'm just not sure what terminolgy is used. From what I've seen; includes, snippets, chunks etc have different meaning in the context of WordPress.

    If I had a little hunk of info, a piece of code, perhaps a sub-navigation menu, for example, that I wanted to include into several certain pages (not the template) how would I do this?

    A related question -to accomplish the same thing- can the content of a "page" appear in another "page"?

    Thanks

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Two basic options:

    1. Install a plugin like runPHP so that you can use PHP within the post/page content area. That gives you maximum flexibility in terms of including files (using PHP's native include function) on an ad hoc basis but it also means that you're limited to display any such included files within a fairly limited area on the final displayed page.

    2. Custom page templates. You can create different templates for various scenarios that incorporate your (normally included) files and then assign these templates to specific pages as needed.

    You can achieve a similar end result using WP conditional tags to add custom code to post archives, single post displays and page templates. The conditional then triggers what is displayed and when. Again, you can use PHP's native include function alongside these conditionals, if that's the way you prefer to work.

    can the content of a "page" appear in another "page"?

    Yes. Again, there are a number of ways of achieving this. It really depends upon exactly what you want to do. You might want to have a look at get_posts, for example.

    Hope that helps.

Topic Closed

This topic has been closed to new replies.

About this Topic