• Resolved trinejuel

    (@trinejuel)


    I have successfully added a full-width Soliloquy slider to my site in header.php.
    I would like to only show the slider on the frontpage (index.php).
    I can’t just add the slider code to index.php after <?php get_header(); ?> because then it only fits the full width of the content column, and I want it to fit the full width of the site.

    How can I specify in the code to only show the slider if it’s the frontpage?

    See my test site for example: https://www.test.bageglad.dk

Viewing 15 replies - 1 through 15 (of 15 total)
  • Try wrapping your code in header.php in this:

    
    <?php
      if (is_front_page()) {
        // Your code for the slider goes here.
      }
    ?>
    

    Check out the is_front_page codex article for more info.

    • This reply was modified 8 years, 1 month ago by linux4me2.
    Thread Starter trinejuel

    (@trinejuel)

    Hi @linux4me2,

    Thank you so much for your answer.
    I think I need some help in how to add the slider code to your snippet.
    I tried a few things, and since I know nothing about php, haven’t managed to make it work ??
    The code for the slider is: <?php if ( function_exists( ‘soliloquy’ ) ) { soliloquy( ‘7917’ ); } ?>

    <?php
    if (is_front_page()) {
    <?php if ( function_exists( ‘soliloquy’ ) ) { soliloquy( ‘7917’ ); } ?>
    }
    ?>
    (yeah, that didn’t work)

    Thanks!

    Give this a try:

    
    <?php
    if (is_front_page()) {
      if (function_exists(‘soliloquy’)) {
        soliloquy(‘7917’);
      }
    }
    ?>
    

    Note that you only need the opening <?php and closing ?> PHP tags if you’re in HTML and not already in PHP, so depending on where you’re putting this in your header.php, you may not need the opening and closing PHP tags I’ve added in the above snippet. For example, if you’re already in PHP, it would just be:

    
    if (is_front_page()) {
      if (function_exists(‘soliloquy’)) {
        soliloquy(‘7917’);
      }
    }
    
    Thread Starter trinejuel

    (@trinejuel)

    Hi linux4me2,

    Thank you so much for your reply.
    I gave your snippet a try, but the slideshow doesn’t show up on any pages now.
    It is the actual blogroll that I want the slideshow to appear on, i.e. https://www.test.bageglad.dk.

    <div id="slideshow">
    
          <?php
    if (is_front_page()) {
      if (function_exists(‘soliloquy’)) {
        soliloquy(‘7917’);
      }
    }
    ?>
    
    </div>

    Hmmm…

    When I look at your page, I see you have a few javascript errors from a Pinterest plugin, and I see the div for your slideshow, but no slider. My understanding is that the is_front_page() function should work either with a latest posts page or with a static home page.

    Here’s what I’d try:

    1. Disable the Pinterest plugin to see if your slider shows up. If so, you may have a conflict between it and Soliloquy.
    2. If not, let’s see if the is_front_page() isn’t giving us the result we want. Add the following to your code block so that it looks like this:
       
      <?php
      if (is_front_page()) {
        echo '<p>is_front_page is true</p>';
        if (function_exists(‘soliloquy’)) {
          soliloquy(‘7917’);
        }
      } else {
        echo '<p>is_front_page is false</p>';
      }
      ?>
      

      If you see the “is_front_page is true” and your slider still isn’t showing up, we know our function to detect the home page is working, and there is an issue with Soliloquy.

    Let’s start with that. With that information, we can see if we can figure out what the problem is.

    Thread Starter trinejuel

    (@trinejuel)

    Hi again,

    I have no Pinterest widgets installed. However, I do have a share plugin that has a Pinterest share button in it, so following your advice I have first deactivated this plugin. The Soliloquy slider still did not appear. Does the javascript error still appear?

    Secondly, I have added your altered code. The homepage does now indeed say “frontpage is true” and the other pages say “frontpage is false”. Still no slider showing.

    • This reply was modified 8 years, 1 month ago by trinejuel.

    The javascript error is now gone, so disabling that share plugin fixed that.

    I am seeing that our is_front_page test works; the home page says is_front_page is true.

    Next step: make sure the Soliloquy conditional statement is working. Try this for your code block:

    
    <?php
    if (is_front_page()) {
      if (function_exists(‘soliloquy’)) {
        echo 'soliloquy function exists';
        soliloquy(‘7917’);
      } else {
        echo 'soliloquy function does not exist';
      }
    }
    ?>
    
    Thread Starter trinejuel

    (@trinejuel)

    Hi,

    I’ve added your altered code.
    The front page now says that Soliloquy function does not exist. Odd!

    Well, that explains why the slider isn’t showing up. Give me a minute to see if I can reproduce that on a test site to see if it’s a problem with the plugin or something specific to your site.

    I tried it on a test site with an otherwise working installation of Soliloquy, and the function soliloquy() doesn’t exist when called in header.php. That’s the problem. It must need to be called within a page template.

    You can confirm that this is the case by editing page.php and putting your code block in it to see if our test shows the soliloquy function exists and the slider appears. The problem will be that your slider probably won’t be full width, but first, let’s make sure I’m correct about the issue.

    Thread Starter trinejuel

    (@trinejuel)

    I discovered the reason why it wasn’t working!

    This code didn’t work because the ’ symbols were wrong.

    <?php
    if (is_front_page()) {
      if (function_exists(‘soliloquy’)) {
        soliloquy(‘7917’);
      }
    }
    ?>

    When corrected to this, it works perfectly and only shows the slider on the frontpage:

    <?php
    if (is_front_page()) {
      if (function_exists('soliloquy')) {
        soliloquy('7917');
      }
    }
    ?>

    Ahh! Nice catch! That’s why one should always use a text-only editor to write code. I didn’t check your quotes.

    It looks good. On my screen, it’s shifted to the left because the slider images are only 1280 px wide. If you don’t want to use wider images for higher-resolution monitors, you can center it over your content by adding the following CSS:

    
    #slideshow {
    	margin: 0 auto;
    	max-width: 1280px;
    }
    
    • This reply was modified 8 years, 1 month ago by linux4me2.
    Thread Starter trinejuel

    (@trinejuel)

    Thank you so much for your patient help, @linux4me2!
    I’ll alter the images for higher resolution, what is the max. size you would recommend?

    You’re welcome. I’m sorry I missed the quotes. I was lazy and just copied your code instead of re-typing it.

    I don’t know that I’d change a thing. It looks really good to me on a 1920 px-wide monitor. The proportions of the images are very nice. If you went wider and kept the proportions, it would push your content down too much, I think. If you kept the height and just went wider, I don’t know if you’d get the same “feng shui” you have now.

    I’m not sure how big you should go. I’ve seen some sites that have full-width sliders use 2000 x 500, and some use 1600 x 230. The sweet spot used to be 1920 px wide. You may want to google it and see what the current recommendations are.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Only show slider on homepage’ is closed to new replies.