@kwight,
Awesome!!! Exactly what I needed!!
Many many thanks!
Will send a sample to show what I am up to when done! :)
Soren
@kwight,
Awesome!!! Exactly what I needed!!
Many many thanks!
Will send a sample to show what I am up to when done! :)
Soren
One thing that came up is that letters have different shapes and might need different settings in position!
Could this be done by html in the "post" to override the settings in CSS? or do I need one php function for each settings?
For example letter "A" and letter "T" needs different settings for the "left" value...
Thanks
Soren
Perhaps one solution could be to use different width of the image to make the position fit.... more work indeed...
You can use the $background variable again to add a unique class for each letter:
$img = '<img class="bg-letter bg-' . strtolower($background) . '" src="' . get_bloginfo('url') . '' . strtolower($background) . '" />';
That way .bg-letter applies to all background letters, and you can use .bg-t to adjust just A or T.
Good luck!
@kwight,
There is one problem... on every single post I get this error in firebug where I am not using the "custom field...
<img class="bg-letter bg-" src="http://digitalworkflow.s3.amazonaws.com/wp-content/uploads/images/.png">
(Failed to load given URL)
In Safari I get the blue box with "? have not checked on IE yet"...
For example you can see this in "www.digitalworkflow.se/bixby-bridge-on-highway-one-california/" when using Safari... it is on the bottom of the post...
Soren
This is an example of the letter in the background I am working on (works beautiful) but also an image of the problem with "?" mark on every post where I am not using any custom field...
http://www.digitalworkflow.se/background_letter/
Soren
Been trying to look into this....
The code seems to expect an png file on every single post, which is not what I want (only when using "background" in custom field). When I try to download the missing image in Safari ("?") on the post and open in finder it tells me that "Safari can’t show the file “png” in the Finder because “png” has not yet been created." so the post is expecting a "png" file. In Firefox you dont see the the "?" mark but when using firebug the following line under "entry-content" is "<img class="bg-letter bg-" src="http://my website.com/wp-content/uploads/images/.png">" this line is greyed out with an error message "Failed to load given URL"
I thought when using the "true statement" ($background = get_post_meta($post->ID, 'background', true);) that when it is "false" nothing is done!?
Is there an "if false" statement missing or needed?
Thanks for all great help
Soren
Did you 'google' the wordpress function call?
get_post_meta will return a single custom field value when the 3rd parameter is 'true'. Which is what you want. You then need a sanity check on $background in case no custom field value has been assigned:
if ( $background <> "" )
// assign the URL into your CSS
else
// don't assign
-Jeff
@Jeff,
I am sorry but my knowledge in php is limited...
Where and how should I put your suggestion in the function that kwight did? I have tried but then the website goes blank or the post disappear...
I google the function call but have so far not find a way to do this...
Thanks
Soren
Right after you get the value into $background from the get_post_meta() call. Assuming you haven't changed much/anything from what he last posted, try this:
function kwight_add_background_letter( $content )
{
if ( is_single() )
{
global $post;
$background = get_post_meta( $post->ID, 'background', true );
if ( $background <> "" )
{
$img = '<img class="bg-letter" src="' . get_bloginfo('url') . '/wp-content/uploads/images/' . strtolower($background) . '.png" />';
$content .= $img;
}
}
return $content;
}
add_filter( 'the_content', 'kwight_add_background_letter' );
If there is a value/letter put into $background, then your $img is calcualted and added onto the $content and returned. If there is no value (when you haven't assigned a letter to the custom field), then the $content is not changed and is returned untouched.
This way the browser will only try to load an image if there really is one and you won't get the broken image icon. (the question mark in Safari)
-Jeff
kwight and Jeff,
Thanks for the explanation Jeff,
I owe you both a BIG thanks, this is one of the best functions I have in hands. Now I can style each post background as I want. This is really great to give a post a more personal touch.
If you are passing my part of the world the beers will be free for sure :)
Soren
Good stuff, glad you have it working. :)
Good luck!
Hello!
Is there a way to get background into the blog pages as well?
Now the background only shows on the single post but not on the blog page!
if ( is_single() )... and I need something like (is_blog)...
Thanks
I got it!
By using:
function kwight_add_background_letter($content) {
if(is_single() || is_home()) {
.......
Would there be a function for making the background image clickable?
where the function has an image you'd wrap it in a link
Instead of setting body background via css, and using body classes to show various backgrounds, it could be done via childtheme function? If so, could you show an example of such a function? Thank you helgatheviking.
sounds like you are asking for something different. try starting a new thread. include what you want to do differently, what you've tried and the results you get versus the results you would like.
Thanks - will do (in a few hours)...
This topic has been closed to new replies.