How to get just the text from custom fields ? (3 posts)

  1. Pewpewdesign
    Posted 4 years ago #

    Hello, I want to use the custom fields as a height and width for a div in my custom made news slider. What code should I put for example in

    <div style="width: <?fancyphpcode>px; height: <?anotherfancycode>px;">

    Thanks in advance.

  2. Navaratnam
    Posted 4 years ago #

    If you have custom fields
    width 100px
    height 60px

    then the code as follows

    $width = get_post_meta($post->ID, 'width', true);
    $height = get_post_meta($post->ID, 'height', true);
    <div style="width: <?php echo $width; ?> height: <?php echo $height;?>">
  3. Alex
    Posted 4 years ago #

    get_post_meta($post_id, $custom_filed_id, true); You can read more here http://codex.wordpress.org/Custom_Fields
    So, if you have custom field id width, then you would use this code to get a value in your template file

    <?php $myWidth = get_post_meta($post->ID, 'width', true);
     <div style="width: <?php echo $myWidth; ?>px; "></div>

Topic Closed

This topic has been closed to new replies.

About this Topic