BTW, take out that redundant php opening and closing tag near the top of your code pasted above. You don't need to close php and immediately open it again.
Rotating headers for ONE category?
(53 posts) (6 voices)-
Posted 1 year ago #
-
Is there not code which just tells it to randomize what's in the directory? I know we use code like that on my site somewhere else so I can easily add images to the directory and not hard code the path. I don't want to have to remember to change the path every time I add an image. I'll look around...thanks.
Syahir...is there a way with what you gave me so far to just tell it to randomize what's in that directory?
Posted 1 year ago # -
Like this...but not sure how to implement
http://ma.tt/scripts/randomimagehttp://ma.tt/scripts/randomimage/
Posted 1 year ago # -
As I said, that code was untested, and it contained errors. This one is tested, and should work:
function graphene_custom_header_image( $image ){ if ( is_category( 'blog' ) ){ /* The script to rotate through possible images here. */ // The directory where the images reside $dir = get_stylesheet_directory() . '/images/custom-headers/'; // Get all images from the $dir above $images = glob( $dir . "*.jpg" ); if ( $images !== false ){ // Pick a random image $key = array_rand( $images ); // Make sure the resulting image is assigned to the $image variable $image = get_stylesheet_directory_uri() . '/images/custom-headers/' . basename( $images[$key] ); } } return $image; } add_filter( 'graphene_header_image', 'graphene_custom_header_image' );Note that the parameter for the
is_category()function can be a category's ID, title, or slug, but it's best to use ID or slug since they are unique, while title may not be unique.Find out how you can support the Graphene theme.
New to the forum? Make sure you read the forum rules.
Like Graphene? Check out Graphene Mobile and Graphene Mobile Neo!Posted 1 year ago # -
I just replaced it with that...but still not sure what to do about a script...
It still shows the main blog images.
Am I doing something wrong?
Still need to plug in a script there?My functions.php file now is this:
<?php function graphene_slider_post_types(){ return array('post', 'page'); } add_filter( 'graphene_slider_post_type', 'graphene_slider_post_types' ); function graphene_custom_header_image( $image ){ if ( is_category( 'blog' ) ){ /* The script to rotate through possible images here. */ // The directory where the images reside $dir = get_stylesheet_directory() . '/images/custom-headers/'; // Get all images from the $dir above $images = glob( $dir . "*.jpg" ); if ( $images !== false ){ // Pick a random image $key = array_rand( $images ); // Make sure the resulting image is assigned to the $image variable $image = get_stylesheet_directory_uri() . '/images/custom-headers/' . basename( $images[$key] ); } } return $image; } add_filter( 'graphene_header_image', 'graphene_custom_header_image' ); function graphene_filter_gettext( $translated, $original, $domain ) { $strings = array( 'View full post' => 'Read More', 'Category Archive: <span>%s</span>' => '<span>%s</span>', ); if ( ! empty( $strings[$original] ) ) { $translations = &get_translations_for_domain( $domain ); $translated = $translations->translate( $strings[$original] ); } return $translated; } add_filter( 'gettext', 'graphene_filter_gettext', 10, 3 ); function laura_sharethis (){ if(!(is_front_page())){ ?> <div id="sharethis"><span class='st_twitter_hcount' displayText='Tweet'></span><span class='st_facebook_hcount' displayText='Facebook'></span><span class='st_fblike_hcount' ></span><span class='st_plusone_hcount' ></span></div> <?php } } add_action( 'graphene_after_post_content', 'laura_sharethis' ); /****** * these next two remove the graphene breadcrumb and then add one * which does not appear on the home page *****/ // has to be called after the action is added add_action ('after_setup_theme', 'wmrt_remove_graphene_bc'); function wmrt_remove_graphene_bc() { remove_action ('graphene_top_content', 'graphene_breadcrumb_navxt'); } add_action('graphene_top_content', 'wmrt_breadcrumb_navxt'); function wmrt_breadcrumb_navxt () { //by calling this at this point is_home() works! if ((function_exists('bcn_display')) && (!(is_front_page()))) { echo '<div class="breadcrumb">'; bcn_display(); echo '</div>'; } }For now, blog (actually Blog) is the title of the category and is unique, I don't anticipate having any other category called "blog". Is the capitalization important?
Posted 1 year ago # -
That script from Matt is another one I have used before and it works like a charm. You can literally put the images anywhere on your website, so long as you call them properly. Matt suggests:
<img src="/dropbox/2003/rotate/rotate.php" alt="A Random Image" />Just drop the script into the same folder with the header images, and call the script instead of a header image. I know, it seems weird to call a script where you would think to call an image, but it works. Just try reloading the page from Matt that you provided.
More helps are available on my blog.
Follow this advice for setting up your blog.
Problems? Questions? Read the forum rules and help us to help you.Posted 1 year ago # -
Ken, I'm still not seeing your images, in any browser. Am I going nuts? or are you??
Posted 1 year ago # -
Well, this one wasn't an image, but a bit of code I forgot to include between backticks. So it's me, not you. (I fixed it.)
BTW, I'm not going nuts; I've been there for some time.
But can you really not see the one image I posted on this forum? Weird.
More helps are available on my blog.
Follow this advice for setting up your blog.
Problems? Questions? Read the forum rules and help us to help you.Posted 1 year ago # -
I see fixed above. But no, I still don't see the image in the other thread. Not in any of my three real browsers I use.... nor in IE (which doesn't surprise me).
Posted 1 year ago # -
raindance, where is the page you're trying to implement this?
Find out how you can support the Graphene theme.
New to the forum? Make sure you read the forum rules.
Like Graphene? Check out Graphene Mobile and Graphene Mobile Neo!Posted 1 year ago #
Topic Closed
This topic has been closed to new replies.

