• Resolved iliaovechkin

    (@iliaovechkin)


    Hi everyone.

    I would like to provide a way for the author to specify the width and height of the post div. Since I am just a beginner with PHP, MySQL and the internal workings of WP I tried copying the functions and the functionaly of how the tags work in WP but I got lost in all the complex functions of the way tags are managed and now I have no idea what to do. Would anyone out there be able to explain to me how I would go about storing this data to then be called inside the loop. Also, is there already some code out there that I could use as a reference?

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I would like to provide a way for the author to specify the width and height of the post div…how I would go about storing this data to then be called inside the loop.

    Perhaps you could do this with custom fields? You could set custom keys of ‘height’ and ‘width’ (with the appropriate values). Then in your templates, before the post div, add this code:

    <?php
    $height = get_post_meta($post->ID, 'height', true);
    $width = get_post_meta($post->ID, 'width', true);
    if( $height || $width ) {
    	$div_style = ' style="';
    	if( $height ) {
    		$div_style .= 'height: ' . $height . ';';
    	}
    	if( $width ) {
    		$div_style .= 'width: ' . $width . ';';
    	}
    	$div_style .= '"';
    } else {
    	$div_style = '';
    }
    ?>

    Then in your post div:

    <div id="post-<?php the_ID(); ?>"<?php echo $style; ?>>

    (Not a fan of inline styles, but it works…)

    Thread Starter iliaovechkin

    (@iliaovechkin)

    great! i also found a nice plugin from c2c (https://www.coffee2code.com/archives/2004/06/30/plugin-get-custom/) that has several functions to fetch custom field data

    for now i guess the custom fields would work, but in the future i want to have a separate form just for post size, because its a bit of a pain to explain how custom fields work to all my users, since you have to type in the key each time and they get assigned to the post separately.

    thank you though – that was a lot of help.

    but in the future i want to have a separate form just for post size

    See if this plugin works for you:

    https://rhymedcode.net/custom-field-gui/custom-field-gui

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Simple data storage/fetching with MySQL’ is closed to new replies.