• Hi.
    Im building a site where there’s an informationbar on the rightside of the site on a couple of pages. Right now i have a left and a right side of the infobar, left holds a key e.g. Born, while right holds the value e.g. 1965. For this i have now made a custom value for the left bar and one for the right, and done this on 10 rows.. This means i have to have 20 custom values to fill 10 rows which to me is very unefficient. I was snooking around the codex,

    <?php
    
      $custom_fields = get_post_custom(72);
      $my_custom_field = $custom_fields['my_custom_field'];
      foreach ( $my_custom_field as $key => $value )
        echo $key . " => " . $value . "<br />";
    
    ?>

    and i thought that maybe you could alter the way it outputs values, and this way add as many custom fields i would want without going through the hassle of adding 20 custom fields and if i would want more rows i would have to edit the theme.. This is a taste of the hell im living in right now.

    <div class="row">
                        	<div class="left">
                            	<?php $key="forestallning_eget1"; echo get_post_meta($post->ID, $key, true); ?>
                            </div>
                            <div class="right">
                            	<?php $key="forestallning_eget1_varde"; echo get_post_meta($post->ID, $key, true); ?>
                            </div><!-- /right -->
                        </div><!-- /row -->
                        <div class="row">
                        	<div class="left">
                            	<?php $key="forestallning_eget2"; echo get_post_meta($post->ID, $key, true); ?>
                            </div>
                            <div class="right">
                            	<?php $key="forestallning_eget2_varde"; echo get_post_meta($post->ID, $key, true); ?>
                            </div><!-- /right -->
                        </div><!-- /row -->

    There’s one problem though. I have a imageslider at the top of these pages, which is controlled by customfields aswell. So i would need it to do this:
    For the slider; only get custom fields named slider, and output only the value of the slider field. This may be one value, or 10.
    For the rightside info; get anything not named slider, and output both key and value, enclosed in div’s. Like this:

    <div class="row">
    <div class="left">$key</div>
    <div class="right>$value</div>
    </div>

    This would make things enormously more smooth and easy. Since i dont know php, im turning to the only option i know and thats the WP forum! I would be seriously thankful if someone would show me how to do this.. Thanks alot in advance!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom post, exclude and include’ is closed to new replies.