• Resolved mickwarnes

    (@mickwarnes)


    I am using Custom Fields to eventually allow other users to put in consistent information on to members pages, which I have done. By default the Field and the Value show inline with a space between them, but I would like all the Values to line up, justified to the left. A bit like if you had a two column table with all the Fields in the left hand column and the Values in the right but justified left to their cells.
    I understand CSS to a degree, but not enough to get this to work.
    I look forward to some assistance
    Thanks
    Mick

Viewing 4 replies - 1 through 4 (of 4 total)
  • If it can be done with CSS, a link to the site where it can be seen might allow someone to help.

    It may require modifying the code that displays the Custom Fields. Can you post a dozen or so lines of that code?

    Thread Starter mickwarnes

    (@mickwarnes)

    The URL for where I currently am is http://hwww.hertsvolleyball.co.uk/hva/teams/local-teams/harriers-st-albans/
    I have changed the meta to replace the unordered list for a <span> in post-template.php

    function the_meta() {
    	global $id;
    
    	if ( $keys = get_post_custom_keys() ) {
    		echo "<span class='post-meta'>n";
    		foreach ( $keys as $key ) {
    			$keyt = trim($key);
    			if ( '_' == $keyt{0} )
    				continue;
    			$values = array_map('trim', get_post_custom_values($key));
    			$value = implode($values,', ');
    			echo "<span class='post-meta-key'>$key:</span> <span class='post-meta-value'>$value</span></br>n";
    		}
    		echo "n";
    	}
    }

    in style.css I currently have the following to format the custom fields, which I know isn’t right, but I have run out of ideas.

    .post-meta-value {color: blue; left:400px; width:400px;}
    .post-meta-key {font-weight: bold; font-size: 110%;  width:200px;}

    I have been experimenting with absolute and relative positioning and just can’t seem to get it right.
    Thanks

    Try this for your function:

    function the_meta() {
    	global $id;
    
    	if ( $keys = get_post_custom_keys() ) {
    		echo "<div class='post-meta-table'>\n";
    		foreach ( $keys as $key ) {
    			$keyt = trim($key);
    			if ( '_' == $keyt{0} )
    				continue;
    			$values = array_map('trim', get_post_custom_values($key));
    			$value = implode($values,', ');
    			echo "<div class='post-meta-row'><div class='post-meta-key'>$key:</div><div class='post-meta-value'>$value</div></div>\n";
    		}
    		echo "</div>\n";
    	}
    }

    And this for your CSS:

    .post-meta-table { display: table; }
    .post-meta-row {
       display: table-row;
    }
    .post-meta-key,
    .post-meta-value {
       display: table-cell;
       padding: 0 0 10px;
    }
    .post-meta-key {
       font-size: 110%;
       font-weight: bold;
       width: 200px;
    }
    .post-meta-value {
       color: blue;
       text-align: left;
       width: 400px;
    }
    Thread Starter mickwarnes

    (@mickwarnes)

    Thanks vtxyzzy
    That has worked perfectly. I was almost there using floats and hadn’t thought about using tables.
    Cheers
    Mick

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Custom Fields formatting’ is closed to new replies.