Forums

Make an image show in the sidebar on the homepage only (17 posts)

  1. danaldinho
    Member
    Posted 2 years ago #

    Hey everyone,

    I want to add an image to my sidebar, but I only want the image to show in the sidebar on my blog's homepage ( http://www.lilwaynehq.com ).

    So for example, when you view a page or a single post on my blog, I don't want the image to show in the sidebar.

    Does anyone know how I would do this?

    Thanks :)

  2. doc4
    Member
    Posted 2 years ago #

    danaldinho,

    Start by placing the following at the top of the homepage ( or Main Index Template / index.php ):

    <?php $thisPage="Index"; ?>

    "Index" can be any name you prefer, but needs to be specific to this page. Next in your sidebar.php file add the code for the image to be included and a little extra php. Something to the effect of:

    <div id="sidebar">
    
    <?php if ($thisPage=="Index") {
          echo "";
          } else {
          echo "<div class="myImage">
                <img src="http://www.image-location.com>
                </div>";
          } ?>
    
    </div>

    The first echo is blank ""; indicating that if this page isn't the homepage something else could happen. Technically you could remove the second echo but I prefer to have options.

  3. danaldinho
    Member
    Posted 2 years ago #

    Hey doc4,

    I did that and then in the sidebar I got this error message:

    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/dannym/public_html/blog/wp-content/themes/LilWayneHQ/sidebar.php on line 6

    I am also trying to do this for some text underneath the image that includes commas.

    So is there a way around this too?

    Thanks :)

  4. danaldinho
    Member
    Posted 2 years ago #

    In fact, I used this code:

    <?php if ($thisPage=="Index") {
          echo "";
          } else {
          echo "<div class="box2"><div id="mpu_banner">
    <img src="http://www.lilwaynehq.com/images/rebirth-sidebar.jpg" alt="Lil Wayne Rebirth Album" width="300px" height="250px" />
    </div></div>";
          } ?>

    And I still got the same error as above.

  5. danaldinho
    Member
    Posted 2 years ago #

    Ok, anyone else got any ideas?

    Thanks :)

  6. danaldinho
    Member
    Posted 2 years ago #

    Please can someone help me with this.

    I can't seem to find a way to do it.

    Thank you

  7. outshine
    Member
    Posted 2 years ago #

    How about this

    <div id="sidebar">
    
    <?php if (is_home()) {
                echo "<div class="myImage">
                <img src="http://www.image-location.com>
                </div>";
          } ?>
    
    </div>
  8. danaldinho
    Member
    Posted 2 years ago #

    Nope, I still got an error message:

    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/dannym/public_html/blog/wp-content/themes/LilWayneHQ/sidebar.php on line 120

  9. Mark / t31os
    Moderator
    Posted 2 years ago #

    Make sure HTML code sits..

    ?>
    // Here
    <?php

    and PHP code sits inside the ...

    <?php
    // PHP code would be here
    ?>

    All PHP code must be inside <?php and ?>, and anything else, outside of those tags..

    This is invalid.

    <div id="sidebar">
    
    <?php if (is_home()) {
                echo "<div class="myImage">
                <img src="http://www.image-location.com>
                </div>";
          } ?>

    Double quote strings must have the double quotes escaped.. but i'd suggest switching for single quotes..

    <div id="sidebar">
    <?php
    if (is_home()) {
      echo '<div class="myImage"><img src="http://www.image-location.com></div>';
    }
    ?>

    Or you can use this method..

    <div id="sidebar">
    <?php if (is_home()) { ?>
      <div class="myImage"><img src="http://www.image-location.com></div>
    <?php } ?>
  10. danaldinho
    Member
    Posted 2 years ago #

    Thanks t31os_

    But do you know what to do with the commas.

    Because there is a box with a paragraph sentence in that I only want to show on the homepage and it has commas in.

    It brings up this error:

    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/dannym/public_html/blog/wp-content/themes/LilWayneHQ/sidebar.php on line 120

  11. Mark / t31os
    Moderator
    Posted 2 years ago #

    Paste the code from that file in a pastebin and report the link back here.
    http://wordpress.pastebin.ca/

    It's just an incorrect character or incorrectly nested/open/closed tags..

  12. danaldinho
    Member
    Posted 2 years ago #

    Is it the code you want that I am using?

    If so, http://wordpress.pastebin.ca/1563253

  13. Mark / t31os
    Moderator
    Posted 2 years ago #

    What's the complete code for that file, sidebar.php ...

  14. danaldinho
    Member
    Posted 2 years ago #

    Including the changes you said to do, here you go:

    http://wordpress.pastebin.ca/1563547

  15. Mark / t31os
    Moderator
    Posted 2 years ago #

    Ok these lines right at the top..

    div id="sidebar" class="grid_6">
    
    <?php
    if (is_home()) {
      echo '<div class="box2"><div id="mpu_banner">
    <p class="welcome"><strong>Welcome to LilWayneHQ.com:</strong> We are the #1 source for Weezy F Baby fans! We give you the latest news, music, pictures, videos, downloads, gossip and plenty more stuff on the greatest rapper alive. Don't forget to bookmark us and view the pages at the top.
    <br /><br />
    <strong>Updates:</strong> Download pages are coming back soon!</p>
    </div></div>';
    }
    ?>

    ..because you're using single quotes (for the echo), in this piece of text..

    Don't forget to bookmark us and view the pages at the top.

    ..the single quote would need to be escaped...

    Don\'t forget to bookmark us and view the pages at the top.

    ... however i'd suggest just switching the chunk of code above to..

    <div id="sidebar" class="grid_6">
    
    <?php if (is_home()) { ?>
    <div class="box2"><div id="mpu_banner">
    <p class="welcome"><strong>Welcome to LilWayneHQ.com:</strong> We are the #1 source for Weezy F Baby fans! We give you the latest news, music, pictures, videos, downloads, gossip and plenty more stuff on the greatest rapper alive. Don't forget to bookmark us and view the pages at the top.
    <br /><br />
    <strong>Updates:</strong> Download pages are coming back soon!</p>
    </div></div>
    <?php } ?>

    ..no need to escape the single quote that way...

  16. danaldinho
    Member
    Posted 2 years ago #

    Thanks so much t31os_, it worked :)

    Appreciate your help.

  17. danaldinho
    Member
    Posted 2 years ago #

    Hey, I'm bumping this because I have another question similar.

    I have a picture that I want to show on all my pages of my WordPress blog except for my homepage.

    Does anyone know the PHP code I will need to wrap around my image code?

    Thanks, appreciate it.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.