Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've built an HTML table that is posted on a page in my site, and I'd like to use that same content inside a blog post (something of an announcement of the table's publication). The table is likely to get updated from time to time, so I'd like to have a single source for maintenance purposes.

Is there a way I can do a one-off embedding of the table's source into the blog post, so that it is always updated when the page is updated? This isn't expected to happen often, so I don't want to put a lot of elbow grease into making this work.

Thanks in advance!

EDIT

SO I made a really short shortcode solution using http://wordpress.org/extend/plugins/shortcode-exec-php/

extract(shortcode_atts(array('arg' => 'default'), $atts));
$id = 2328;
$post = get_post( $id );
return apply_filters('the_content', $post->post_content );

Thanks to everyone who helped. I don't have rep to upvote answers, but i will when I get more points.

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

Create a shortcode to embed the content. This will always be synchronized.

Sample code from an older project. Just updated. :)

GitHub: https://gist.github.com/3380118 · This post in German (auf Deutsch) on my blog.

<?php # -*- coding: utf-8 -*-
/**
 * Plugin Name: T5 Embed Post Shortcode
 * Description: Embed any page, post or custom post type with shortcode.
 * Plugin URI:  http://wordpress.stackexchange.com/q/62156/73
 * Version:     2012.08.17
 * Author:      Thomas Scholz
 * Author URI:  http://toscho.de
 * License:     MIT
 * License URI: http://www.opensource.org/licenses/mit-license.php
 *
 * T5 Embed Page Shortcode, Copyright (C) 2012 Thomas Scholz
 */

add_shortcode( 'embed_post', 't5_embed_post' );

/**
 * Get a post per shortcode.
 *
 * @param  array $atts There are three possible attributes:
 *         id: A post ID. Wins always, works always.
 *         title: A page title. Show the latest if there is more than one post
 *              with the same title.
 *         type: A post type. Only to be used in combination with one of the
 *              first two attributes. Might help to find the best match.
 *              Defaults to 'page'.
 * @return string
 */
function t5_embed_post( $atts )
{
    extract(
        shortcode_atts(
            array (
                'id'    => FALSE,
                'title' => FALSE,
                'type'  => 'page'
            ),
            $atts
        )
    );

    // Not enough input data.
    if ( ! $id and ! $title )
    {
        return;
    }

    $post = FALSE;

    if ( $id )
    {
        $post = get_post( $id );
    }
    elseif( $title )
    {
        $post = get_page_by_title( $title, OBJECT, $type );
    }

    // Nothing found.
    if ( ! $post )
    {
        return;
    }

    return apply_filters( 'the_content', $post->post_content );
}

Just make sure not to embed two posts vice versa.

share|improve this answer
    
thanks, this looks great. trying it out right now –  patrickgamer Aug 17 '12 at 17:34
add comment

I would look at using the WordPress SHortcode API:

http://codex.wordpress.org/Shortcode_API

This will allow you to create something along the lines of [announceTable] or such so that you can call the table's data and styling as represented in the original page (which is also the Shortcode). Then when you want to update the table you update the Shortcode itself.

I hope I understood what you wanted and that this helps. Happy programming!

share|improve this answer
    
this is just what i need. just looking to see how to request the page in question. thanks –  patrickgamer Aug 17 '12 at 17:29
    
add comment

If you are looking for a quick and easy solution you might want to have a look at the WP-Table Reloaded plugin.

That allows users to created as many (or as little) tables as they like that are then displayed by adding a simple shortcode in the page/post content.

As it's linked to via the shortcode they user can then update the table and it will change everywhere it's linked to.

I've used it with a company website where the content is made up of a lot of technical tables and it's been great as where have been any changes to specifications I just go to the admin and update the table and it's then updated everywhere.

share|improve this answer
    
does this allow for tool-tips? –  patrickgamer Aug 17 '12 at 17:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.