WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Fields for Template (problem, seems like a bug) (6 posts)

  1. Muten
    Member
    Posted 5 years ago #

    Hey

    I'm using WP as a CMS for this website right here:
    http://greenlife.ciplex.ws/our-roots
    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?

  2. jord_t
    Member
    Posted 5 years ago #

    What code are you using to call your custom fields?

  3. Muten
    Member
    Posted 5 years ago #

    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') ?>">

  4. jord_t
    Member
    Posted 5 years ago #

    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.

  5. jord_t
    Member
    Posted 5 years ago #

    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>

  6. Muten
    Member
    Posted 5 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic