• I have WordPress 2.1.3 already installed and I’m working on my theme. What I would like to do is include existing page (by ID or name) – not post page! – into theme as one of few sidebar boxes. WordPress as CMS will let me update separate pages and frontpage’s boxes :>

    !Don’t wanna make it home page – it’s gonna be just a ‘in-box’ at sidebar content page.

    Anyone have idea or clue what function should I use ?

Viewing 13 replies - 1 through 13 (of 13 total)
  • It sounds to me like you want to be able to control a piece of your sidebar content via a Page in WP’s admin, right?

    If so, I typically do the following:

    1. Download and install the Improved Include Plugin
    2. Get the ID of the WP Page that you’d like to include in your sidebar.
    3. Go into your sidebar.php template file (or wherever you’re keeping the code for your sidebar) and insert the following:
      <?php iinclude_page(#); ?>
      where # = the Page ID

    That should do it for you.

    Thread Starter patdynek

    (@patdynek)

    Right, but is it possible to do it without using third-party plugins ? I’m preety sure there is somebody who figured out how to minimalize usage of plugins and get the content from WP Page as include.

    Meanwhile I’ll test this plugin.

    Thanks clicknathan!

    There’s probably a more correct way of doing this but I got satisfactory results using

    <?php
    $homepagefeatures = $wpdb->get_results("SELECT post_content FROM $wpdb->posts WHERE ID = '49'");
    
    foreach ($homepagefeatures as $homepagefeature) {
    echo $homepagefeature->post_content;
    }
    ?>

    You’d change ID = ’49’ to the correct page id.

    A more ‘WordPress way’ of doing the above:

    <?php
    $my_page = new WP_Query("page_id=49");
    $my_page->the_post();
    the_content();
    ?>

    Thanks for the addition Kafkaesqui.

    In my particular situation I have the edit_post_link() in the footer of the page (Example here).

    The extra content (references) is loaded from another page into the index page. Obviously, you won’t see the edit link unless you are logged in.

    Using the method above, the edit link goes to the ‘references’ page (the loaded extra content) in stead of the ‘correct’ page you’d want to edit when clicking the edit link. With a custom query the edit link keeps its correct value.

    I’m not great with php & mysql, but thought that might be helpful : )

    Just need to rewind things…

    <?php
    $my_page = new WP_Query("page_id=49");
    $my_page->the_post();
    the_content();
    rewind_posts();
    ?>

    yup, I guess I’ve got some reading up to do : )
    Not getting the difference between the two methods yet, guess there’s some caching going on?

    Anyway, to get the content without enclosing tags I adjusted it to:

    <?php
    $my_page = new WP_Query("page_id=49");
    $my_page->the_post();
    §my_content = get_the_content();
    echo $my_content;
    rewind_posts();
    ?>

    I’m wondering why this method is better than the plugin method? I am using Improved Include Plugin to do this with several chunks of content on my homepage as well as throughout the site. I realize that there is a certain amount of overhead involved with loading a plugin, but is it significant?

    I will probably continue to use Improved Include because some users are actually including posts in their page content, so being able to do it in the editor rather in the template is a bonus. Just curious, really.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    I realize that there is a certain amount of overhead involved with loading a plugin, but is it significant?

    Yes, actually, plugin overhead can indeed be rather significant. How big is the plugin code? All that code has to be loaded into memory, parsed, interpreted, etc. Just to do something that about 5 lines of code will do? Seems a bit over the top, no? Also consider the code that has to be run to find and load the plugin in the first place, there’s some overhead there as well.

    If the plugin is doing something that you can do yourself in less than, say, 30 lines of code, then it’s probably faster to do it yourself.

    Now, at the same time, if you’re using this plugin in more than one place, for several different things, then it could well be worth the trouble. But a plugin for a single small code use case is often overkill.

    Great, thanks. That’s very good to know. Like I said, I am using the plugin in several places, so I will need to keep it. But it does worry me, I have a whole bunch of plugins running, I will try to optimize a bit.

    If I were to use the code mentioned above on my homepage, but keep the plugin running for the benefit of the other pages on the site, would there be any performance benefit? Or with the overhead of the plugin running anyway, I might just as well use it?

    By the way, the site I am talking about is storycorps.net. Most of the content blocks on the page are individual posts or pages, so that’s a fairly significant number of database hits to put that page together.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    If I were to use the code mentioned above on my homepage, but keep the plugin running for the benefit of the other pages on the site, would there be any performance benefit? Or with the overhead of the plugin running anyway, I might just as well use it?

    That’s hard to answer. It depends on the plugin and what it does. Even if I knew what plugin it was, it would take some rather heavy analysis to determine that.

    There’s no simple answer, of course. It’s certainly possible (probable for many cases) for a plugin to be slower than roll-your-own-code approaches. But it depends on the situation.

    On the whole, whole page caching (like wp-super-cache) makes this sort of thing irrelevant, since it makes the pages into static ones that refresh every so often. If the site is really dynamic though, then yeah, this can be an issue if you get lots of hits.

    WP-super-cache is a good idea. I tried WP-Cache but found it unreliable. I do want to get a decent caching solution in place-our traffic has been unpredictable, but we’ve been getting linked from some pretty big sites, so I need to be prepared for a sudden Boing-Boing effect.

    Go into your sidebar.php template file (or wherever you’re keeping the code for your sidebar) and insert the following:
    <?php iinclude_page(#); ?>
    where # = the Page ID
    This is a good idea.

    [sig moderated]

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Including wordpress cms page into theme’ is closed to new replies.