Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Test listing of Custom Fields
- $styles = <<<EOSTYLES
- <style type="text/css">
- .one-car {
- width: 50%;
- margin: auto;
- }
- .car-attribute {
- width: 30%;
- float: left;
- }
- .clearboth {
- clear: both;
- }
- </style>
- EOSTYLES;
- echo $styles;
- $attrs = array('Color','Make','Model');
- $args = array(
- 'cat' => 107,
- 'posts_per_page' => 10,
- 'ignore_sticky_posts' => 1,
- );
- query_posts($args);
- if (have_posts()) {
- while (have_posts()) {
- the_post();
- $custom_fields = get_post_custom();
- //print_r($custom_fields);
- //break;
- $fields = array();
- $all_cf_keys = array_keys($custom_fields);
- foreach ($attrs as $key) {
- if (in_array($key, $all_cf_keys)) {
- $fields[$key] = $custom_fields[$key][0];
- }
- }
- $cf_keys = array_keys($fields);
- if ($fields) {
- echo "<div class='one-car'>\n";
- foreach ($attrs as $attr) {
- $class = strtolower($attr);
- $value = (in_array($attr,$cf_keys)) ? $fields[$attr] : ' N/A ';
- if(in_array($attr,$cf_keys)) {
- echo "<div class='car-attribute car-$attr'>$value</div>\n";
- }
- }
- echo "</div><!-- /one-car -->\n";
- echo "<div class='clearboth'></div>\n";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement