ThemeShaper Forums » Thematic

[closed]

Different backgrounds on post

(50 posts)
  • Started 12 years ago by soren
  • Latest reply from daveread
  • This topic is resolved
  1. @kwight,

    Awesome!!! Exactly what I needed!!

    Many many thanks!

    Will send a sample to show what I am up to when done! :)

    Soren

    Posted 12 years ago #
  2. 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

    Posted 12 years ago #
  3. Perhaps one solution could be to use different width of the image to make the position fit.... more work indeed...

    Posted 12 years ago #
  4. kwight
    Member

    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!

    Posted 12 years ago #
  5. @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

    Posted 12 years ago #
  6. 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

    Posted 12 years ago #
  7. 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

    Posted 12 years ago #
  8. 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

    Posted 12 years ago #
  9. @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

    Posted 12 years ago #
  10. 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

    Posted 12 years ago #
  11. 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

    Posted 12 years ago #
  12. Good stuff, glad you have it working. :)

    Posted 12 years ago #
  13. kwight
    Member

    Good luck!

    Posted 12 years ago #
  14. 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

    Posted 12 years ago #
  15. I got it!

    By using:
    function kwight_add_background_letter($content) {
    if(is_single() || is_home()) {

    .......

    Posted 12 years ago #
  16. Would there be a function for making the background image clickable?

    Posted 11 years ago #
  17. where the function has an image you'd wrap it in a link

    Posted 11 years ago #
  18. 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.

    Posted 11 years ago #
  19. 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.

    Posted 11 years ago #
  20. Thanks - will do (in a few hours)...

    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.