Forum Replies Created

Viewing 15 replies - 1 through 15 (of 36 total)
  • OK, the only way I’ve done this is to force PHP5 for my entire WordPress site by adding this line to the .htaccess file in the root directory:

    AddHandler application/x-httpd-php5 .php

    It works for me, but I don’t have anything whch requires PHP4 since I changed theme and dropped some plugins, otherwise I’m not sure how you’d do it as WordPress can’t recognise .php5 plugins…

    ?

    Thread Starter shirohagen

    (@shirohagen)

    The background image name, including file extension (ie ‘image.jpg’) is held in a custom field ‘background’ which can be set for any page or post on the site when you write it. The template just reads this in and uses it for the CSS style:

    <!-- Decide on background graphic for the current page or post -->
    
    <?php 
    
    // Capture the custom field "background" //
    $background_graphic = get_post_meta($post->ID, "background", $single = true); 
    
    // For the search results page
    if (is_search()) {
    	// Use a image from the homepage //
    	$background_graphic = get_post_meta(4, "background", $single = true);
    }
    // For the category Portfolio //
    elseif (in_category('12')) {
    	// If there is no value use a generic one from Page 9 //
    	if ($background_graphic[0]=="") {
    	$background_graphic = get_post_meta(9, "background", $single = true);
    	}
    }
    // For the category Play //
    elseif (in_category('25')) {
    	// If there is no value use a generic one from Page 13 //
    	if ($background_graphic[0]=="") {
    	$background_graphic = get_post_meta(13, "background", $single = true);
    	}
    }
    // For the page Info and its children //
    elseif (is_page('11') or $post->post_parent=="11") {
    	// If there is no value use a generic one from Page 11 //
    	if ($background_graphic[0]=="") {
    	$background_graphic = get_post_meta(11, "background", $single = true);
    	}
    }
    // For the category Blog //
    elseif (in_category('16')) {
    	// If there is no value use a generic one from Page 12 //
    	if ($background_graphic[0]=="") {
    	$background_graphic = get_post_meta(12, "background", $single = true);
    	}
    }
    ?>
    
    <!-- Body style to control page backgrounds using WP custom fields -->
    
    <style>
    body { background-image: url(<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $background_graphic; ?>);
    	background-repeat: repeat;
    	background-attachment: fixed;
    }
    </style>

    This code is in the header.php file and is a bit more complex here as I wanted subpages to inherit the parent background image if no specific one was specified, hence all the if, then stuff. For example blog posts don’t have their own background images specified, they use the overall background taken from the blog front page.

    But basically it is very simple, the custom field is read from the page or post into a variable and then used directly in a CSS style definition.

    Dan.F: The images aren’t all optimised or implemented properly yet. For pages with more rigourous content, I’m finding the most subtle backgrounds are best so as not to compete, but for a few key pages, like the homepage or the ‘about me’ page I’m making more of a stament by choosing an impactful image. My photography is something I want to give a sense of. For the individual projects, the background image will be a pattern or detail from the project itself. The difficulty is currently in getting either very large images so the edges are out of view down to a small file size, or using smaller ones but tiling them well.

    Hope this helps anyone trying to do something similar…

    ?

    Anyone?

    ?

    Thread Starter shirohagen

    (@shirohagen)

    An update to this thread, which still sends me hits regularly, so obviously a lot of graphic designers are interested in using WordPress as a CMS for their portfolios…

    I’ve ditched the evolved Hemingway theme I was using, and having gained a lot of experience by getting down and dirty with the Hemingway code, I’ve made more of an individual statement with my first ever 100% original WordPress theme.

    The new site houses all the same content, but uses far fewer plugins and less php files. Hopefully the content is more clearly organised and the whole site is more graphic and less generically ‘bloggy’

    The idea is that any post can have a custom background image which is drawn from a custom field, allowing each project to set a tone over the whole browser window. If no custom field exists, a generic background image is used. I’m still working it out but I’m 90% there.

    Any comments or constructive advice is welcomed…

    ?

    Thread Starter shirohagen

    (@shirohagen)

    OK, I think I’ve got it:

    <!– Decide on background graphic for the current page or post –>

    <?php

    // Capture the custom field “background” //
    $background_graphic = get_post_meta($post->ID, “background”, $single = true);

    // For the category Portfolio //
    if (in_category(’12’)) {
    // If there is no value use a generic one from Page 9 //
    if ($background_graphic[0]==””) {
    $background_graphic = get_post_meta(9, “background”, $single = true);
    }
    }
    // For the category Play //
    elseif (in_category(’25’)) {
    // If there is no value use a generic one from Page 13 //
    if ($background_graphic[0]==””) {
    $background_graphic = get_post_meta(13, “background”, $single = true);
    }
    }
    // For the category Blog //
    elseif (in_category(’16’)) {
    // If there is no value use a generic one from Page 12 //
    if ($background_graphic[0]==””) {
    $background_graphic = get_post_meta(12, “background”, $single = true);
    }
    }
    // For the page Info and its children //
    elseif (is_page(’11’) or $post->post_parent==”11″) {
    // If there is no value use a generic one from Page 11 //
    if ($background_graphic[0]==””) {
    $background_graphic = get_post_meta(11, “background”, $single = true);
    }
    }

    ?>

    <!– Body style to control page backgrounds using WP custom fields –>

    <style>
    body { background-image: url(<?php bloginfo(‘stylesheet_directory’); ?>/images/<?php echo $background_graphic; ?>); background-repeat: repeat;}
    </style>

    Seems to be working fine…

    ?

    Thread Starter shirohagen

    (@shirohagen)

    Thanks for the tip, I had found this in the codex actually, I’ve been using it to set my background image:

    <style>
    body { background-image: url(<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo get_post_meta($post->ID, "background", $single = true); ?>); background-repeat: repeat;}
    </style>

    This works fine.

    But what I really need is a way to put the value for “background” into a variable so that I can evaluate it with if else type statements:

    If: A custom field called “background” exists and contains a filename
    Then: Set variable ‘$background_image’ to that filename
    Else: Set variable ‘$background_image’ to a generic filename

    …after that I can use $background_image as a variable in my style definition:

    <style>
    body { background-image: url(<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $background_image; ?>); background-repeat: repeat;}
    </style>

    That way I can specify a background image on a per-post basis, but if I don’t have one, a generic background will be used.

    I understand the logic, it’s literally the correct PHP I’m having trouble with, can anyone help?

    ?

    Thread Starter shirohagen

    (@shirohagen)

    Fantastic! Sorry, forgot about the other post, I’m heading there now…

    ?

    Thread Starter shirohagen

    (@shirohagen)

    Hi guys, thanks for the kind words, the site is properly launched now and I’m starting to get hits…

    In answer to jp978’s question, I used categories to separate content for the site, reserving the tags for actually browsing. I have then used pages to present just portfolio category entries for example, and then customise the presentation of each.

    I’m still finishing the site info page so check that out for some hints as to how I worked it out.

    ?

    Thread Starter shirohagen

    (@shirohagen)

    Thanks for the compliments, I’m glad you like it. The site info page isn’t finished yet, so that’s all still a bit all over the place. I think I’ll try to keep it short and sweet! ??

    ?

    Just bumping this thread as I need to do this too, the SimplePie plugin requires PHP5 in order to format RSS feed output, but if I use an .htaccess hack to put my entire WordPress folder under PHP5, it freaks out and breaks everything. For this reason I was wondering about solely running the SimplePie plugin in PHP5…

    ?

    I modified by .htaccess file to enforce PHP5 and my entire site turned to gibberish and code fragments. I took this to mean that WordPress didn’t run in PHP5, but if it does, then something else awfully strange was going on…

    ?

    Thread Starter shirohagen

    (@shirohagen)

    Hello

    In case anyone is interested, I did eventually find a way to do this, although I’m still working on the site.

    To display the image only I used the Image Extractor plugin:
    https://www.dynamick.it/image-extractor-765.html

    And then to display the text, I used The_Extract Reloaded plugin, which gives you a bit more control than the standard excerpt:
    https://guff.szub.net/2005/02/26/the_excerpt-reloaded/

    That’s pretty much it, it allowed me to put the image under the text on the portfolio pages and have a nice wide graphic separate from the info.

    Hope this helps…!

    ?

    Thread Starter shirohagen

    (@shirohagen)

    Hello

    In case anyone is interested, I did eventually find a way to do this, although I’m still working on the site.

    To display the image only I used the Image Extractor plugin:
    https://www.dynamick.it/image-extractor-765.html

    And then to display the text, I used The_Extract Reloaded plugin, which gives you a bit more control than the standard excerpt:
    https://guff.szub.net/2005/02/26/the_excerpt-reloaded/

    That’s pretty much it, it allowed me to put the image under the text on the portfolio pages and have a nice wide graphic separate from the info.

    Hope this helps…!

    ?

    Thread Starter shirohagen

    (@shirohagen)

    Hello

    In case anyone is interested, I did eventually find a way to do this, although I’m still working on the site.

    To display the image only I used the Image Extractor plugin:
    https://www.dynamick.it/image-extractor-765.html

    And then to display the text, I used The_Extract Reloaded plugin, which gives you a bit more control than the standard excerpt:
    https://guff.szub.net/2005/02/26/the_excerpt-reloaded/

    That’s pretty much it, it allowed me to put the image under the text on the portfolio pages and have a nice wide graphic separate from the info.

    Hope this helps…!

    ?

    Care to actually leave the answer here then?

    ?

Viewing 15 replies - 1 through 15 (of 36 total)