Home> CMS Tutorial> WordPress> body text

How to get Sina weather in WordPress

藏色散人
Release: 2020-01-10 09:59:06
Original
2578 people have browsed it

How to get Sina weather in WordPress

How to get Sina weather in wordpress?

wordpress Get Sina weather to create wordpress sidebar weather (wordpress plug-in)

Recommendation: "wordpress tutorial"

WordPress gets Sina weather and creates a blog sidebar weather. Just put the following php code directly into the sidebar. Of course, it can also be done in other places.

There are two ways to get IP. I have commented out the complex ones. If you want to use the complex ones, just remove the comments and then comment out the simple ones.

The code is as follows:

desc)) { $loc = $location->city; $full_loc = $location->province . $location->city . $location->district . $location->isp; } else { $loc = $location->desc; } return $loc; } $city = getIPLoc_sina("$SA_IP");

$citycode = mb_convert_encoding($city, "gb2312", "utf-8");

$doc = new DOMDocument(); if (!@$doc->load("http://php.weather.sina.com.cn/xml.php?city=" . $citycode . "&password=DJOYnieT8234jlsK&day=0")) { echo "Get data failed!!\n"; return; }

$city = $doc->getElementsByTagName("city")->item(0)->nodeValue; $stat1 = $doc->getElementsByTagName("status1")->item(0)->nodeValue; $chy_shuoming = $doc->getElementsByTagName("chy_shuoming")->item(0)->nodeValue; $tmp1 = $doc->getElementsByTagName("temperature1")->item(0)->nodeValue; $tmp2 = $doc->getElementsByTagName("temperature2")->item(0)->nodeValue; $date = $doc->getElementsByTagName("savedate_weather")->item(0)->nodeValue; $pollution_l = $doc->getElementsByTagName("pollution_l")->item(0)->nodeValue; $gm_s = $doc->getElementsByTagName("gm_s")->item(0)->nodeValue;

echo '

'; ?>
Copy after login

CSS style

.sina-weather-content{border:1px solid #D14836;font-size:12px;line-height:14px;position:relative} .sina-weather-city{background:#D14836;color:#FFFFFF;font-size:14px;font-weight:600;left:-1px;padding:5px 15px;position:absolute;top:5px;z-index:2;display:inline} .sina-weather-body{overflow:hidden;padding:45px 15px 15px} .sina-weather-body p{margin-bottom:10px} .sina-weather-tem{color:#000000;font-size:36px;font-weight:700;line-height:36px;padding-top:10px} .sina-weather-text{color:#666666;display:block;margin-top:10px} .stat-w{color:#555555;font-family:Microsoft Yahei;font-size:18px;font-style:italic;font-weight:600;line-height:10px} .entry-meta{position:relative;font-size:12px;font-size:12px;margin-top:-15px;padding:10px 0;text-transform:uppercase} .entry-meta a{color:#666}
Copy after login

The above is the detailed content of How to get Sina weather in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!