WordPress.org

Forums

php code widget (5 posts)

  1. sanstepsan
    Member
    Posted 2 years ago #

    <?php
    $target = mktime(0,0,0,4,7,2011);
    $today = time();
    $difference = ($target-$today);
    $days = (int)($difference/86400);
    
    if ((date('m') == 4) && (date('d') == 7))
    {
    print "<h2>Game On!</h2>";
    }
    else
    {
    print "<h2>$days days to go!</h2>";
    }
    ?>

    I have the following code which works fine - how do I add html code to make the $days in a red font?

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    wrap it in a span either with a css class or an inline style?

    print "<h2><span class="red_days">$days</span> days to go!</h2>";

    then in style.css:
    h2.red_days { color: red; }

    or

    print "<h2><span style="color: red;">$days</span> days to go!</h2>";
  3. sanstepsan
    Member
    Posted 2 years ago #

    Alchymyth
    I tried your second option but as soon as the span is inserted the code fails to show anything at all.
    Could it be because the code is within the PHP Code widget?

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    my bad - i need to pay more attention to the quotation marks:

    print "<h2><span style='color: red;'>$days</span> days to go!</h2>";

    or

    print "<h2><span class='red_days'>$days</span> days to go!</h2>";

  5. sanstepsan
    Member
    Posted 2 years ago #

    Alchymyth

    Single quotes made all the difference.

    Don't know why but many thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags