0

My client wants to have several pages in which he can edit small, separate parts of a Wordpress page. For example, there is a callout box in the upper left corner. There is also a small piece of text showing contact information in the lower right corner. I'd like to be able to have all of these pieces of text editable in the same place.

My idea is to have a post structured using shortcodes; something like this:

[top-callout]
This is the top callout text.
[/top-callout]

[bottom-contact-info]
341 Address Rd.
City Comma State 23422
[/bottom-contact-info]

[other-text]
...
[/other-text]

and so on. Is there a way to extract the content of the shortcodes into loop variables? That way in a theme php file I could do something like:

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    ...
    <?php echo $post->top_callout; ?>
    ...
    <?php echo $post->bottom_contact_info; ?>
    ...
<?php endwhile; ?>

Or, is there a better way to do this?

2

A much better way to do that would be to use custom fields so you could pull the data in the loop by using get_post_custom or get_post_meta.

And to make it even easier on your client you can create your own meta box either by code or using a plugin like verve meta box with separate textareas ,input fields, or even WYSIWYG editors.

1
  • i use WPAlchemy for creating my metaboxes, but that's definitely the way to go. Aug 13 '11 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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