- This topic is empty.
-
How do I get rid of that empty white space? Please look at the right area in the banner
http://mstoicthemes.com/about-us/Thanks
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hi , I m creating theme on wordpress. And I m having a problem in options page. But my problem is not a wordpress problem its just a PHP problem.
I have created a form so user can upload images/SWF which is working great however when they delete the URL of the image I want the image to disappear however it leaves a whitespace. I have checked the database I have noticed that when the image path value is deleted by the user, it still leave a white space which messes my condition, so if I check if ($value==”) I would have to check if($value==’ ‘).
//meta_value is the image/swf url which I m having problems with.
if (has_post_thumbnail() && $meta_value==”) {
the_post_thumbnail();
}elseif(!has_post_thumbnail() && $meta_value==”){ ?>
How do I get rid of that empty white space? Please look at the right area in the banner
http://mstoicthemes.com/about-us/
Thanks
thats not a php problem its a css one your post thumbnail has a width of 590px and your container has a width of 971px.
the_post_thumbnail accepts also numeric values so you can decide the width and height of the thumbnail being displayed
http://codex.wordpress.org/Function_Reference/the_post_thumbnail
just to see it your self setting the width of the img element to 100% takes the whole space but the image is streched
Actually if you look at the condition I have mentioned above, the 590px image will only show when there is swf file available. If
if(has_post_thumbnail() && !$meta_value==”){
//then only show the small image so I can adjust the SWF and the image.
}
if the SWF file path value is empty then use 971px image
elseif(!has_post_thumbnail() && $meta_value==”){ ?>
//show the image which is 971px large.
So that’s problem since a white space is coming from the database my condition is being incorrect. because ther is difference between ” and ‘ ‘. So this is PHP problem
Thanks for replying.
make sure your meta value is properly saved to the database and retrieve it with get post meta
http://codex.wordpress.org/Function_Reference/get_post_meta
you could also use the empty() php function combined with trim() to remove whitespaces
Okay Thanks a lot . Actually I figured something, its not the worpdress’s issue, When I delete the url from the input and if I forget a white space the problem begins because a white space is saved in the database and it spits the same out, so lets forget wordpress. How do I prevent this from happening, or how do I trim it with php? because in wordpress we dont run a query to insert values into the databata, we just give the input a name and wordpress takes care of the rest.
I dont know how to catch the value to trim it on its way to database.
Okay I got it I used
and now I m checking the condition on $meta_value_final and its doing what I want it to do
All thanks to you pixelgrid
i suppose you are using a plugin for the metaboxes which adds as many as the user needs.Unless you change teh plugin files you cant but retriving this
with retrieve the value from the database and in case it is empty or just whitespace it will remove it and will correctly say it has no value.
$meta_value = get_post_meta(get_the_ID,’meta_value_name’);
$meta_value = trim($meta_value);
if(empty($meta_value) && has_post_thumbnail() ){ }
if(empty($meta_value) && !has_post_thumbnail() ){ }
if you have written the add meta box just take care when you insert the retrieved meta value to the value attribute of the input to not have any white space its very common
nvm @pixelgrid beat me to it
: )
I m not using any plugin , I have written the code from a tutorial http://themefoundation.com/wordpress-meta-boxes-guide/
Where do I use this trim() ??
Here is the whole code
function example_custom_meta() {
add_meta_box( ‘example_meta’, ‘Featured SWF’, ‘example_meta_callback’, ‘page’, ‘side’, ‘default’ );
}
add_action( ‘add_meta_boxes’, ‘example_custom_meta’ );
/* Outputs the content of the meta box */
function example_meta_callback( $post ) {
//To verify the input and for security
wp_nonce_field( basename( __FILE__ ), ‘example_nonce’ );
$example_stored_meta = get_post_meta( $post->ID );
?>
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ ‘example_nonce’ ] ) && wp_verify_nonce( $_POST[ ‘example_nonce’ ], basename( __FILE__ ) ) ) ? ‘true’ : ‘false’;
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// Checks for input and saves if needed
if( isset( $_POST[ ‘meta-image’ ] ) ) {
update_post_meta( $post_id, ‘meta-image’, $_POST[ ‘meta-image’ ] );
}
} // end example_meta_save()
add_action( ‘save_post’, ‘example_meta_save’ );
?>
* Loads the image management javascript
*/
function example_image_enqueue() {
global $typenow;
if( $typenow == ‘page’ ) {
wp_enqueue_media();
// Registers and enqueues the required javascript.
wp_register_script( ‘meta-image’, get_template_directory_uri() . ‘/meta-image.js’, array( ‘jquery’ ) );
wp_localize_script( ‘meta-image’, ‘meta_image’,
array(
‘title’ => ‘Choose or Upload an Image’,
‘button’ => ‘Use this image’,
)
);
wp_enqueue_script( ‘meta-image’ );
} // End if
} // End example_image_enqueue()
add_action( ‘admin_enqueue_scripts’, ‘example_image_enqueue’ );
?>
in the link you provided when you write this line