Support » Fixing WordPress » Need code for text to only appear homepage

  • I have a blog: http://www.amomslove.com where I want to place an ad in the left hand sidebar. The person prefers to
    only be on my homepage and not all through the site. My sidebar is a widget. What code can I add that lets the her
    link just appear on my home page?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You can use conditional tags
    http://codex.wordpress.org/Conditional_Tags

    Try to use this in sidebar.php, after
    <div id="sidebar">

    <?php if (is_home()) {
            echo "<a href='http://www.example.com'><img src='path/to/image/image.jpg'</a>";
    } ?>
    Thread Starter amomslove

    (@amomslove)

    Thank you buddha, but I put this code up..it isn’t an image but just a text link…so I put this up but it doesn’t seem to work:
    <p align=center>
    <?php if (is_home()) {
    echo “Google“;
    } ?>

    http://www.amomslove.com

    @amomslove – Well, luckily you didn’t need an image! I just realized that I didn’t close the img tag in the earlier example… [blush]
    it should have been, for those who need an image

    <?php if (is_home()) {
            echo "<a href='http://www.example.com'><img src='path/to/image/image.jpg'></a>";
    } ?>

    for just text, use:

    <p style="text-align:center;">
    <?php if (is_home()) {
            echo "<a href='http://www.example.com'>Example</a>";
    } ?>
    </p>

    Thread Starter amomslove

    (@amomslove)

    Buddha, I put up the second one and it still doesn’t work.
    Do you make all your images on your blog? They are incredible.

    AMomsLove.com

    @amomslove – I see, looked at your source code. That would not work inside a text widget, because there is php code. And you need php to create the conditional tag (since you only want the link in the home page)

    Look at this plugin
    http://wordpress.org/extend/plugins/php-code-widget/

    It works just like a text widget, but it parses php as well.

    The other alternative is to hard code it into the template, sidebar.php

    Re: blog, all theme images are mine, except for post pics. 🙂

    so I want to do something like this as well, but what i want is i have a piece of music that i want to play only on the home page….

    the code i have is this:
    <?php if !(is_home()) {
    <embed src=”http://www.atouchoflove.ca/audio/HomeAloneSample.mp3&#8243; autostart=”true” loop=”true” hidden=”true”>
    } ?>

    is that right? i’m so not a php programmer, but this doesn’t work anyways…can you see something that stands out…as to why it won’t work?

    i’m putting it in the main index.php file directly under:
    <?php get_header(); ?>

    Please help…Thanks
    tracy

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Need code for text to only appear homepage’ is closed to new replies.