JennyLeez wrote:Both the short and long forecast are repeating themselves.
Jenny, do you wan to remove the short forecast (texts) from both your 'Current Conditions' (index.htm) page and 'Forecast' (forecast.php) pages?
The most flexible and permanent way to do that would be to install a new 'switches' (a variable) into the code of the Weather Underground forecast script (WU-forecast.php) - so that, when the short forecast 'switch' is true the short forecast is displayed, otherwise the short forecast is not displayed...
If you are familiar enough with HTML and PHP, the modification is quite easy - but, remember that the modified script will now become incompatible with futur releases...
Three parts of the "
WU-forecast.php" script (version 1.19 - 09-Sep-2011) need to be modified.
The first modification - the code for short forecasts (displayed under the forecast images) is located between lines 746 and 752:
Code: Select all
<tr valign ="top" align="center">
<?php
for ($i=$startIcon;$i<$finIcon;$i++) {
print "<td style=\"width: $wdth%; text-align: center;\"><span style=\"font-size: 8pt;\">$WUforecastcond[$i]</span></td>\n";
}
?>
</tr>
A 'switch' (decision making code) needs to be added - thus the resulting line of code will be (between lines 746 and 754):
Code: Select all
<?php if ($PrintMode and $printShortForecast) { ?>
<tr valign ="top" align="center">
<?php
for ($i=$startIcon;$i<$finIcon;$i++) {
print "<td style=\"width: $wdth%; text-align: center;\"><span style=\"font-size: 8pt;\">$WUforecastcond[$i]</span></td>\n";
}
?>
</tr>
<?php } ?>
The second modification - the code for 'switching' the long forecasts on/off from an external request (script/template) is located between lines 646 and 651:
Code: Select all
if (isset($doPrintTextWU)) {
$printText = $doPrintTextWU;
}
if (isset($_REQUEST['text']) ) {
$printText = substr(strtolower($_REQUEST['text']),0,1) == 'y';
}
The code for 'switching' the short forecasts on/off from an external request (script/template) must be added (between lines 746 and 754):
Code: Select all
if (isset($doPrintForecastWU)) {
$printShortForecast = $doPrintForecastWU;
}
if (isset($_REQUEST['shortforecast']) ) {
$printShortForecast = substr(strtolower($_REQUEST['shortforecast']),0,1) == 'y';
}
if (isset($doPrintTextWU)) {
$printText = $doPrintTextWU;
}
if (isset($_REQUEST['text']) ) {
$printText = substr(strtolower($_REQUEST['text']),0,1) == 'y';
}
And finally, the third modification - the default 'switch' settings for what is displayed is located between lines 629 and 631:
Code: Select all
$printHeading = true;
$printIcons = true;
$printText = true;
The code for the default 'switch' setting for the short forecasts must be added (between lines 629 and 632):
Code: Select all
$printHeading = true;
$printIcons = true;
$printShortForecast = true;
$printText = true;
OK, to use the new 'switch'...
In the file/template you use to get the Weather Underground forecast (forecast.php), you must add the 'switch' when needed. I will be using the "wxforecast.php" template as an example (between lines 73 and 78):
Code: Select all
<?php
$doIncludeNWS = true; // handle advforecast2.php include
$doIncludeWU = true; // handle WU-forecast include also
$doInclude = true; // handle ec-forecast and WXSIM include also
$doPrint = true; // ec-forecast.php setting
include_once($SITE['fcstscript']); ?>
The new code with all the 'switches' (between lines 73 and 84):
Code: Select all
<?php
$doIncludeNWS = true; // handle advforecast2.php include
$doIncludeWU = true; // handle WU-forecast include also
$doInclude = true; // handle ec-forecast and WXSIM include also
$doPrint = true; // ec-forecast.php setting
//
$doPrintHeadingWU = true; // display the heading
$doPrintIconsWU = true; // display the forecast icons
$doPrintForecastWU = true; // display the short forecasts
$doPrintTextWU = true; // display the long forecasts
//
include_once($SITE['fcstscript']); ?>
I tested the code as I was writing this 'tutorial' and heading/icons/short forecasts/long forecasts were displaying (or not displaying) depending on the values placed into the 'switches'.
