Support » Themes and Templates » Custom Fields for Template (problem, seems like a bug)

  • Resolved Muten



    I’m using WP as a CMS for this website right here:
    This is an example page, not post.

    My problem right now is that each sub-page has its own color theme and image for the content area. I do not want to allow the client to mess up the templates by leaving a ton of markup in each individual page.

    My solution was going to be to use custom fields (as well as the Get Custom Field Values plugin) to tell my template what page it is on and what css to use or what image to place on the right side.

    I have two custom fields. One called “wrapper” that I’m using as a variable to switch the IDs for certain div’s and thus I can control it on a per-page basis thru my stylesheet afterwards. The second field is called “secondary”, which is what I’m using for the accompanying image next to the content area.

    Do note that I am using my custom fields outside of the loop because to put the loop elsewhere would give the client too much control and would probably mess up the site in due time.

    The bug that I think I’m experiencing is only allowing my pages to have one value for each key. Any time I put a new value for “wrapper” on the page I need it on it either a) does not update at all or it, b) changes it for all of the pages instead of the one I’m updating. The same goes for the “secondary” key.

    Can anybody help me figure out if I’m updating the Custom fields wrong? Or if this is a bug I need to work around? or do I need to give up on this technique?

Viewing 5 replies - 1 through 5 (of 5 total)
  • What code are you using to call your custom fields?

    I’m using the get_recent_custom function from the Get Custom Field Values plugin.

    It goes like this for the secondary key:

    <img src="<?php echo c2c_get_recent_custom('secondary'); ?>" title="Stock" />

    And like this for one of the wrapper ones (I have it a couple times similar to this):

    <div id="primary<?php echo c2c_get_recent_custom('wrapper') ?>">

    Is it neccessary for you to use this plugin? If this were me, i would place this inside the loop <?php $VARIABLE = get_post_meta($post->ID, 'CUSTOM FIELD KEY NAME', true); ?> and then echo the image where ever you wanted it on the page using the following code <?php echo $VARIABLE; ?>. As for the div ids for each page you could use some conditional tags<?php if ( is_page(‘contact’) ) { echo ‘ id=”contact”‘; } ?>`. Or alternatively you could use the code above to call a custom id for the div for each page.

    A little bit of extra information, if you are going to use custom fields for the div id, make sure this part is placed outside the loop;

    <?php $div_id = get_post_meta($post->ID, 'page_div_id', true); ?>

    Then you could just have this as your code;

    <div id="<?php echo $div_id; ?>">Bla Bla</div>

    beautiful. I didnt get a chance to say thanks, but you helped me finish the whole project. the design is protected from the client and is completely functional on wordpress too. thanks a bunch!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Fields for Template (problem, seems like a bug)’ is closed to new replies.