Syahir Hakim
KeymasterKuala Lumpur, Malaysia
When not perched on my workspace, I tremendously enjoy hiking in the bushes and climbing mountains. They serve as much-needed refuges from the pretense of cities.
Forum Replies Created
-
Admin
Graphene Options > Display > Navigation Menu Display Options > Disable description in Header Menu
Admin
In reply to: Question: Remove the text powered by WordPress and the Graphene Theme
November 1, 2011 at 10:03 pm #19223Add this code to the Custom CSS option:
#developer {
display: none;
}Admin
OK, try this:
function graphene_custom_header_image( $image ){
if ( is_category() || is_single() ){
/* The script to rotate through possible images here. */
// Get the current category
if ( $cat = get_query_var( 'cat' ) ){
$cat = get_the_terms( $cat, 'category' );
$cat = $cat[1]->slug;
} else {
global $post;
$cat = get_the_category( $post->ID );
$cat = $cat[0]->slug;
}
// The directory where the images reside
$dir = get_stylesheet_directory() . '/images/custom-headers/' . $cat;
if ( is_dir( $dir ) ){
// Get all images from the $dir above
$images = glob( $dir . "/*.jpg" );
if ( $images ){
// 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/$cat/" . basename( $images[$key] );
}
}
}
return $image;
}
add_filter( 'graphene_header_image', 'graphene_custom_header_image' );That will get random images for each category according to their slug. E.g. for the
Uncategorizedcategory, it will get the images fromgraphene-child/images/custom-headers/uncategorized/.Admin
You can use a Static Front Page.
Admin
In reply to: Yontoo react virusprogram on my pc when I am not connected to my webbsite
November 1, 2011 at 9:23 pm #19213What’s the URL to your site? FYI, the theme has got nothing to do with Yontoo, and if it’s there it definitely doesn’t originate from the theme.
Admin
Like I said, it can be done and the code needs to be modified a bit to accommodate your use case, but first, we need to make sure that the part where the code randomly picks the image out works first.
Read my post again, particularly this part:
Quote:However, it’s pretty easy to make the changes, but you’ve got to first make sure that the part of the code where it gets the random image work first.The “If that works, it will rotate the header images for *all* pages and posts in your site.” part is a sure-fire way to make sure that that part of the code works. Then we’ll get to getting it to work according to categories.
Also, next time, try editing your forum post to add more info rather than posting multiple posts one after the other. That’ll make it easier to follow the discussion without too much text to read through.
Admin
Just insert it in WP Admin > Appearance > Graphene Options > Display > Custom CSS.
Admin
Okay, firstly, I was under the impression that you want the header to rotate in the archive page, i.e. the page that lists all posts that belong to the category “Blog”.
Secondly, the slug for your “Blog” category appears to be
juicy-travels-blog, which is why the code didn’t work. It was assuming that the slug for your “Blog” category isblog.Thirdly, of course it wouldn’t work for individual posts that are assigned to the “Blog” category. That’s not what it’s meant for.
However, it’s pretty easy to make the changes, but you’ve got to first make sure that the part of the code where it gets the random image work first. Try using this code:
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' );If that works, it will rotate the header images for *all* pages and posts in your site.
Admin
raindance, where is the page you’re trying to implement this?
Admin
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.
