Help Add slider to additional specific pages using conditional tags

Hi,
My problem is very similar to this https://colorlibsupport.com/t/slider-on-all-pages-2/ post which is resolved however I wanted to use conditional tags to allow for 2 other pages to also show the slider Conditional Tags « WordPress Codex

I had tried using || is_page( 238 ) || is_page( 239 ) in the code but when I do it and add the code to the child-theme functions file the site breaks (so I must be doing something badly). I also created a child them inc/extras.php file

Currently in my functions.php child theme file is the following code that I use to disable the captions on the slider

<?php

// Queue parent style followed by child/customized style
add_action( 'wp_enqueue_scripts', 'func_enqueue_child_styles', 99);

function func_enqueue_child_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_dequeue_style('sparkling-style');
    wp_enqueue_style( 'sparkling-style',
        get_stylesheet_directory_uri() . '/style.css',
        array('parent-style')
    );
}

/**
 * Featured image slider, displayed on front page for static page and blog
 */
function sparkling_featured_slider() {
  if ( is_front_page() || is_page( 238 ) || is_page( 239 ) && of_get_option( 'sparkling_slider_checkbox' ) == 1 ) {
    echo '';
      echo '<ul>';

        $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 '';
                  if ( get_the_title() != '' ) echo ''. get_the_title().'';
                  if ( get_the_excerpt() != '' ) echo '' . get_the_excerpt() .'';
              echo '</div>';
              echo '</li>';
              endwhile;
            endif;

      echo '</ul>';
    echo ' </div>';
  }
}

I hope you can help.

Hi @bharte,

I hope you are well today and thank you for your question.

You can try achieving this by using the attached custom child theme of Sparkling theme that contains some custom code.

Best Regards,
Movin

Thanks. I tried that without success.

I even tried changing conditionals to

is_page() || is_post() ) in case I was wrong with the page id’s but it still didn’t show.

I am using the right conditionals? One of the pages I am trying to get it to display on has this in the source:
body class="home page-template-default page page-id-239" which I presume makes it page id 239.

Any ideas?

Ok…I have a little more information now.

( ( is_front_page() || is_page() ) works but not on the 2 pages I wanted it to work with those were the 2 additional translation pages of the homepage using WPML plugin.

Basically I wanted the slider to appear in the header area of the site.com site.com/es and site.com/nl (2 languages es and nl)
Adding ( ( is_front_page() || is_page() ) to the child themes makes the slider appear on all site.com/pages but not the translated pages. Is there conditionals to use for these pages?

the dev page is http://cab.brianharte.co.uk and you’ll see the slider is currently on ALL the english pages (default language) but not on either homepage spanish or dutch or the dutch About Us page. No other secondary language pages exist yet to test with.

Thanks. I tried that without success.

It is working fine on my test site so could you please share me the page URLs from your site where it is not displaying correctly so that i can troubleshoot it?

the dev page is http://cab.brianharte.co.uk and you’ll see the slider is currently on ALL the english pages (default language) but not on either homepage spanish or dutch or the dutch About Us page. No other secondary language pages exist yet to test with.

This is because that plugin changes the home page URL to another page so please check whether that translator plugin provides any function to check whether the page is translated home page so that you can use it in the above code condition.

If it doesn’t provide then you can just display the slider on all pages by using the solution posted in the following reply.

https://colorlibsupport.com/t/slider-on-every-pages/

Thanks. Currently the child theme is set to show on all pages using ( ( is_front_page() || is_page() ) and you can see it on both the default language homepage http://cab.brianharte.co.uk/ and the about page http://cab.brianharte.co.uk/about-us/ you will see it is not on the secondary language homepage http://cab.brianharte.co.uk/nl/ or the secondary language about page (I have only made that additional page in the secondary language) http://cab.brianharte.co.uk/nl/about-us/

I can make an admin account for you and and a backup if you wanted to look around as it is a dev site.

The end goal is to have the slider on the homepage and the homepage of the 2 languages http://cab.brianharte.co.uk/nl/ and http://cab.brianharte.co.uk/es/ and no other pages. I set to all pages simply to test if that made it appear and it didn’t.

Also I disabled the child theme/reenabled the parent Sparkling theme and it was the same without slider on the secondary language pages.

The slider is displaying on the other English language pages along with home page so it seems your first question is resolved.

Regarding your second question about displaying slider on all language pages, i have already answered this in my previous reply so please read it.

Thanks. I posted on the WPML support forums and it appears I was missing one step from my actions to make it work. I know others have had similar issues so I wanted to post the fix below in case future people are also missing that same step…

  1. Go and translate the homepage slider category into all languages. https://wpml.org/documentation/getting-started-guide/translating-post-categories-and-custom-taxonomies/
  2. Now go to every slide post and duplicate them in all languages.
  3. Go to front-end and check the slider, it should work properly.

Basically, although I had translated the homepage PAGES in to the multiple languages I had not translated the taxonomy of post categories and neither the slider posts. Once that was done the slider showed in all languages.

I’ve removed is_page() from my child theme edits so that now it is back to where it should be with it showing on only the frontpages of all the languages.

Thanks for your help.

Thanks for helping out here in this forum by sharing the solution.

You are most welcome here :slight_smile: