Forum Replies Created
-
Am I possibly missing something basic and obvious about how categories work?
I mean if I assign any post to a category “abc”, then I want to create a directory of random/rotating headers relevant to that category “abc” that’s what I’m after.
Like what if a post/page category is “sky diving” and all posts or pages are assigned to that category “sky diving”…then I want to assign the header images to randomly rotate from a directory of photos called “images/custom-headers/skydiving”. I’m just saying something that seems like it should be simple for anyone to do. Instead of ONE limited featured image for a post or page, I want to assign posts/page to a category, like blog or sky diving, and have more than one photo be the header image.
Am I not explaining it well? 🙂 Sorry if so.
Thanks Syahir.
emmmm…sorry if I didn’t explain it well.
The point has always been…to have rotating/random headers from a directory for a particular category.
Sorry if that was not clear?
Yup these:
But I still see only the original headers on the new blog test post which is assigned to the “blog” category…
http://juicytravels.com/category/juicy-travels-blog/
http://juicytravels.com/blog-post-test/
(from above)
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?
Like this…but not sure how to implement
http://ma.tt/scripts/randomimagehttp://ma.tt/scripts/randomimage/
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?
Here is the path I have to the images
From 1-24 in the directory
And they show up live if I put in that path the browser
But not in the header spot…
So…missing the script must be the issue?
Not sure what to use for the script?
Thank you for your patience with me!
I changed Blog back to blog. Still none of the images in the images/custom-headers directory are showing up in the header spot…
I’m sure I missed something…oh like the SCRIPT I don’t know what to use 🙂
?
Ok I must have missed a step 🙂
Here is what in my child functions.php file now:
<?php
function graphene_slider_post_types(){
return array('post', 'page');
}
add_filter( 'graphene_slider_post_type', 'graphene_slider_post_types' );
?>
<?php
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[$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>';
}
}I uploaded a folder /images/custom-headers/
in my child theme folder
With the new headers in it.
But I still see only the original headers on the new blog test post which is assigned to the “blog” category…
http://juicytravels.com/category/juicy-travels-blog/
http://juicytravels.com/blog-post-test/
Ok so two questions:
1. Should I have capitalized Blog in your code as I did? Was trying to make it match exactly when it didn’t work, but maybe that is not right in PHP?
2. Still don’t know what to do for the:
/* The script to rotate through possible images here. */
Thank you for your help 🙂
Oh I like your treat 🙂 Happy Halloween! I like chocolate too…
Ok so you are saying
1. paste that code into my child functions.php file
2. make a new folder /images/custom-headers/ and put the images there.
And that’s all?
Trying now…
