BuddyBoss Home – Web › Support Forums › Themes › Boss. theme › Limiting Cover Photos
Tagged: cover photos
- This topic has 19 replies, 5 contibutors, and was last updated 9 years, 8 months ago by Arnold.
-
Question
April 3, 2015 at 12:20 am #38455@
AnonymousThe stock cover photos are very nice and the landscape ones particularly fit the style of my site. How can I limit the stock cover photos to a select amount?
Answers
April 3, 2015 at 9:05 am #38478@alyssa-buddyboss
AlyssaParticipant@ryanmaler what do you mean to limit to a select amount?
April 3, 2015 at 10:40 am #38485@
Anonymous@tjchester I have to take another look through them, but I believe there are 17 that I like as random default cover photos. I would like to eliminate the the others from randomly being set so that only the ones that go with the style of my site appear.
April 4, 2015 at 9:55 am #38511@alyssa-buddyboss
AlyssaParticipant@ryanmaler currently we have 21 images. I think all the information you are looking for is starting on line 263 of buddyboss-inc/cover-photo.php
April 4, 2015 at 12:47 pm #38519@
Anonymous@tjchester I copied buddyboss-inc into my child-theme and edited cover-photo.php. I changed the random number generator from (1, 23) to (1, 17) because I would like to work with a specific 17 cover photos. My question is how do I move the cover photos into the child theme? Should I copy the entire images folder from the parent or just the cover-photo folder from the parent since the child theme already has an images folder? If I copy just the cover-photo folder do I place that in the images folder in the child?
April 5, 2015 at 11:27 am #38538@
AnonymousHi Ryan, it is a good idea to provide your own stock images
replace line 270
$filename = $buddyboss->tpl_dir.'/images/cover-stocks/'.$random_num.".jpg";
with
`$dir_cover = get_stylesheet_directory();
$filename = $dir_cover.’/images/cover-stocks/’.$random_num.”.jpg”;
if (!file_exists($filename)) {
$filename = $buddyboss->tpl_dir.’/images/cover-stocks/’.$random_num.”.jpg”;
}`
inside cover-photo.phpyou can upload your images inside child theme folder inside images/cover-stocks folder
with that approach it will check child folder first and if file name do not exist it will check that parent theme folder.we will add this patch in future updates.
Regards
Varun DubeyApril 5, 2015 at 6:03 pm #38541@
Anonymous@vapvarun Thanks!
April 12, 2015 at 11:29 pm #38850@
Anonymous@vapvarun let me run by you really quick the steps I took just to double check I did this correctly.
First, I made a copy of the entire buddyboss-inc folder to put in my child theme. I put that in there because cover-photo.php is located in the buddyboss-inc folder and I learned from tj chester in the past that you must put the entire route to the file you are editing into the child theme. I then edited line 270 of cover-photo.php as instructed by you. I am using 11 random cover stock photo, so I changed the random number generator in cover-photo.php to (1, 11) from (1, 23).
Second, I copied the entire images folder into the child theme. I then deleted all of the cover stock photos in the cover-stocks folder and put my 11 jpeg images in.
There isn’t really a way to check this except for seeing what cover photos pop up, so I wanted to check my process with you. Does this sound like I did it correctly? Only these 11 cover photos will show by default now?
April 13, 2015 at 12:29 am #38852@
AnonymousUpdate:
Please read previous post, but I must have done something wrong in my process. This isn’t urgent, just noting that I got a buddyboss cover stock photo that isn’t in my child theme cover-stocks folder. My process described above should be pretty close. Please let me know where I went wrong.
April 13, 2015 at 8:27 am #38869@alyssa-buddyboss
AlyssaParticipant@ryanmaler you are unable to copy this file to your child theme. It must be made in the parent theme. As stated above we will try to make this something you can edit within the child theme in the future, but in the mean time you must manually make this change in the parent theme and update during each update. Sorry for the inconvenience.
April 13, 2015 at 10:53 am #38880@
Anonymous@tjchester okay. I understand now. Thank you.
April 13, 2015 at 5:01 pm #38888@
AnonymousHere is a long post. It’s maninly code though, I figured it would be easiest just to show you the whole section of the code I’m dealing with. I only modified the section @vapvarun recommended and $random_num = rand(1, 11);. I’m sure its just a minor error, could you point it out for me please. Also, I have my 11 stock photos number 1 – 11 in my cover-stocks folder inside of the image folder of the child theme.
/* * Upload Stock Sample Attachment and return the ID. * @return <int> ID of attachment **/ function buddyboss_cover_photo_get_stock_sample() { global $buddyboss; $random_num = rand(1, 11); //currently we have 11 images. $random_num = apply_filters("buddyboss_photo_cover_random_stock_num",$random_num); //pick the random image $dir_cover = get_stylesheet_directory(); $filename = $dir_cover.’/images/cover-stocks/’.$random_num.”.jpg”; if (!file_exists($filename)) { $filename = $buddyboss->tpl_dir.’/images/cover-stocks/’.$random_num.”.jpg”; } $filename = apply_filters("buddyboss_cover_photo_stock_pick_filename",$filename); // Check the type of file. We'll use this as the 'post_mime_type'. $filetype = wp_check_filetype( basename( $filename ), null ); // Get the path to the upload directory. $wp_upload_dir = wp_upload_dir(); //copy it copy( $filename, $wp_upload_dir['path'] . '/' . basename($filename) ); $filename = $wp_upload_dir['path'] . '/' . basename($filename); //new path // Prepare an array of post data for the attachment. $attachment = array( 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), 'post_mime_type' => $filetype['type'], 'post_title' => 'Cover Photo Stock Image', 'post_content' => '', 'post_status' => 'inherit' ); // Insert the attachment. $attach_id = wp_insert_attachment( $attachment, $filename, 0 ); require_once( ABSPATH . 'wp-admin/includes/image.php' ); $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data ); return $attach_id; }
April 14, 2015 at 11:31 am #38917@alyssa-buddyboss
AlyssaParticipant@ryanmaler check your code this
’
and this'
are very different characters. use'
and make the other characters apostrophes.April 14, 2015 at 12:24 pm #38923@
AnonymousThat took care of it. Thanks @tjchester @vapvarun
April 16, 2015 at 9:16 pm #39024@alyssa-buddyboss
AlyssaParticipantGreat! I’ll close this out.
- The question ‘Limiting Cover Photos’ is closed to new replies.