ThemeShaper Forums » Thematic

Need to add custom field data into page content area

(8 posts)
  • Started 4 years ago by elshaddai
  • Latest reply from elshaddai
  • This topic is not resolved
  1. I'm looking for a way to add some text to a single page's main content area via custom fields.

    Basically, I want to show a pull quote to the side of a page's content. I would like to use custom fields as my client has a habit of being a little too aggressive in their WYSIWYG editing of the content area. I can't help that, but if I can prevent them from killing the pull quotes by putting the data in custom fields, I'd like to. Similarly, I realize that there are pull quote plugins and will use one of those if this doesn't work, but I'd like to explore my approach if possible.

    I have successfully created the custom fields and can display them directly following the content area ('<?php the_content() ?>') by manually putting the appropriate code in the template php file:

    '<div id="feature-quote">
    <?php $key1="feature-quote"; echo get_post_meta($post->ID, $key1, true); ?>
    <div id="feature-quote-cite">
    <?php $key2="feature-quote-cite"; echo get_post_meta($post->ID, $key2, true); ?>
    </div>
    </div>'

    However, I've not been able to figure out how to filter this block of content into the_content(). Ideally, I'll be floating it on the right side of the content, about halfway between the top and bottom of the content.

    Posted 4 years ago #
  2. Hi,

    this should be something like:

    function my_content($content) {
        $content .= 'My Content';
        return $content;
    }
    add_filter('the_content', 'my_content');

    'My Content' would be your code.

    This is the general way to add something to the_content. Don't know if the final result will work for you.

    Chris

    Posted 4 years ago #
  3. Thanks, Chris. The filter works overall in terms of adding something to the_content, though doing a straight replace of My Content with my <div> code doesn't produce the right results. I'll have to figure out how to get those php statements to work in the functions file.

    Posted 4 years ago #
  4. amygail
    Member

    This post may be helpful (?)
    http://themeshaper.com/action-hooks-wordpress-child-themes/

    The first example shows a function with a php statement

    Posted 4 years ago #
  5. Sorry .. you need to copy the page.php to your child theme's directory and edit it there.

    Chris

    Posted 4 years ago #
  6. Will look through the other pages and add a similar scheme to page.php and the rest which might be missing.

    Chris

    Posted 4 years ago #
  7. amygail
    Member

    I do something sort of like this with a custom page template. I wouldn't have a clue how to insert it into the middle of the content though... (I'd try to float in in there with css)

    Would using a plugin ( I use and like http://wordpress.org/extend/plugins/stray-quotes/)
    that would allows you to insert a shortcode into the post content still leave too much room for trouble?

    Posted 4 years ago #
  8. > Sorry .. you need to copy the page.php to your child theme's directory and edit it there.

    Yep - that's what I had been doing - I just couldn't get the custom data into the_content()...

    @amygail - we didn't need random quote behavior, so I've settled on using the plugin, "Simple Pull Quote", which does almost exactly what I needed. I just added some CSS for the cite tag and my client has agreed to be careful with editing around the shortcodes...

    Posted 4 years ago #

RSS feed for this topic

Reply

You must log in to post.