BuddyBoss Home – Web Support Forums Themes Boss. theme Limiting Cover Photos

Tagged: 

Viewing 15 posts - 1 through 15 (of 20 total)
  • Question

    #38455

    Anonymous
    @

    The 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

    #38478

    Alyssa
    Participant
    @alyssa-buddyboss

    @ryanmaler what do you mean to limit to a select amount?

    #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.

    #38511

    Alyssa
    Participant
    @alyssa-buddyboss

    @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

    #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?

    #38538
    @vapvarun

    Hi 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.php

    you 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 Dubey

    #38541

    Anonymous
    @

    @vapvarun Thanks!

    #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?

    #38852

    Anonymous
    @

    Update:

    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.

    #38869

    Alyssa
    Participant
    @alyssa-buddyboss

    @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.

    #38880

    Anonymous
    @

    @tjchester okay. I understand now. Thank you.

    #38888

    Anonymous
    @

    Here 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;
    }
    #38917

    Alyssa
    Participant
    @alyssa-buddyboss

    @ryanmaler check your code this and this ' are very different characters. use ' and make the other characters apostrophes.

    #38923

    Anonymous
    @

    That took care of it. Thanks @tjchester @vapvarun

    #39024

    Alyssa
    Participant
    @alyssa-buddyboss

    Great! I’ll close this out.

Viewing 15 posts - 1 through 15 (of 20 total)
  • The question ‘Limiting Cover Photos’ is closed to new replies.