• Resolved bgcyam

    (@bgcyam)


    Hi! First of all, I really like this layout. I’ve been searching for something like this for a really long while, it’s great.

    One thing that would put it closer to 100% perfect is if I could make the slider appear on all pages & posts, not only the front page.

    I made a child theme, and tried to tweak the functions.php code via that, but I wasn’t successful. Help would be most appreciated, thank you!!

    This is what I put in my child theme functions.php file:

    <?php
    
    // Add slider CSS only if is front page ans slider is enabled
      if( ( is_home() || is_front_page() || is_page() || is_single() ) && of_get_option('sparkling_slider_checkbox') == 1 ) {
    		wp_enqueue_style( 'flexslider-css', get_template_directory_uri().'/inc/css/flexslider.css' );
      }
    
    // Add slider JS only if is front page ans slider is enabled
    	if( ( is_home() || is_front_page() || is_page() is_single() ) && of_get_option('sparkling_slider_checkbox') == 1 ) {
    		wp_enqueue_script( 'flexslider-js', get_template_directory_uri() . '/inc/js/flexslider.min.js', array('jquery'), '20140222', true );
    	}
    
    // Flexslider customization
      if( ( is_home() || is_front_page() || is_page() is_single() ) && of_get_option('sparkling_slider_checkbox') == 1 ) {
        wp_enqueue_script( 'flexslider-customization', get_template_directory_uri() . '/inc/js/flexslider-custom.js', array('jquery', 'flexslider-js'), '20140716', true );
      }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author Silkalns

    (@silkalns)

    Child theme functions.php files doesn’t overwrite Parent theme functions.php file like it would happen with other files such assingle.php, page php and others.

    You can’t also overwrite these script enqueues and you need to de-enqueue them first and then register them again.

    Here is how you can get rid of default ones:

    /**
     * Function to remove default slider scripts
     */
    function sparkling_dequeue_script() {
        wp_dequeue_script( 'flexslider-customization' );
        wp_dequeue_script( 'flexslider-js' );
    }
    add_action( 'wp_print_scripts', 'sparkling_dequeue_script', 100 );
    
    /**
     * Function to remove default slider CSS.
    */
    function sparkling_dequeue_style() {
        wp_dequeue_style( 'flexslider-css' );
    }
    add_action( 'wp_print_styles', 'sparkling_dequeue_style', 100 );

    Now you can enqueue these scripts without conditional formatting that makes sure that these scripts are loaded on the front page.

    Also you will have to copy/paste slider function from Parent theme extras.php and remove conditional formation from that one as well. But that’s the simplest part here.

    Thread Starter bgcyam

    (@bgcyam)

    Thanks so much. I still can’t get this to work. Could there be an error in my original code to load the scrips on all the pages?

    Thread Starter bgcyam

    (@bgcyam)

    This is the code I’m using now:

    <?php
    
    /**
     * Function to remove default slider scripts
     */
    function sparkling_dequeue_script() {
        wp_dequeue_script( 'flexslider-customization' );
        wp_dequeue_script( 'flexslider-js' );
    }
    add_action( 'wp_print_scripts', 'sparkling_dequeue_script', 100 
    
    );
    
    /**
     * Function to remove default slider CSS.
    */
    function sparkling_dequeue_style() {
        wp_dequeue_style( 'flexslider-css' );
    }
    add_action( 'wp_print_styles', 'sparkling_dequeue_style', 100 );
    
    // Add slider CSS only if is front page ans slider is enabled
    
    if( ( of_get_option('sparkling_slider_checkbox') == 1 ) { 
    
    wp_enqueue_style( 'flexslider-css', get_template_directory_uri
    
    ().'/inc/css/flexslider.css' );
      }
    
    // Add slider JS only if is front page ans slider is enabled
    
    if( ( of_get_option('sparkling_slider_checkbox') == 1 ) 
    
    wp_enqueue_script( 'flexslider-js', get_template_directory_uri() 
    
    . '/inc/js/flexslider.min.js', array('jquery'), '20140222', true 
    
    );
    	}
    
    // Flexslider customization
      if( ( of_get_option
    
    ('sparkling_slider_checkbox') == 1 ) {
        wp_enqueue_script( 
    
    'flexslider-customization', get_template_directory_uri() . 
    
    '/inc/js/flexslider-custom.js', array('jquery', 'flexslider-js'), 
    
    '20140716', true );
      }
    
    /**
    
    * Featured image slider, displayed on front page for static page 
    
    and blog
    
    */
    
    function sparkling_featured_slider() {
      if ( of_get_option( 
    
    'sparkling_slider_checkbox' ) == 1 ) {    echo '<div 
    
    class="flexslider">';
          echo '<ul class="slides">';
    
    $count = of_get_option( 'sparkling_slide_number' );
    
    $slidecat =of_get_option( 'sparkling_slide_categories' );
    
    $query = new WP_Query( array( 'cat' =>$slidecat,'posts_per_page' 
    
    =>$count ) );
            if ($query->have_posts()) :
              while 
    
    ($query->have_posts()) : $query->the_post();
    
              echo 
    
    '<li>';
                if ( (function_exists( 'has_post_thumbnail' )) 
    
    && ( has_post_thumbnail() ) ) :
                  echo 
    
    get_the_post_thumbnail();
                endif;
    
                  echo 
    
    '<div class="flex-caption">';
                    echo '<a href="'. 
    
    get_permalink() .'">';
                      if ( get_the_title() != 
    
    '' ) echo '<h2 class="entry-title">'. get_the_title().'</h2>';
    
                  if ( get_the_excerpt() != '' ) echo '<div 
    
    class="excerpt">' . get_the_excerpt() .'</div>';
    
    echo '</a>';
                  echo '</div>';
    
                  endwhile;
    
             endif;
    
              echo '</li>';
          echo '</ul>';
        echo 
    
    ' </div>';
      }
    }

    I get the error: Parse error: syntax error, unexpected ‘{‘ in /[…]/wp-content/themes/sparkling-child/functions.php on line 22

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying slider on all pages’ is closed to new replies.