Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Wordpress blog question


  • Please log in to reply

#1
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 33,101 posts
I want to add this to one of the pages in my blog, to display the weather in my area, but I can't figure out where to put it and how.
<?php $mfgetweather->get_weather('nlxx0015', 'Rotterdam', 'icon,temp,high,low,dayforecast'); ?>

Wordpress version 2.6.2
Plugin MFGetweather 1.6.0 (is activated)
  • 0

Advertisements


#2
Major Payne

Major Payne

    Retired Staff

  • Retired Staff
  • 5,307 posts
Don't use WordPress, but is the php at least working for you now online and you just need to dress it up a little by controlling the positioning with HTML/CSS?
  • 0

#3
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 33,101 posts
Hi Ron,

No the problem is, there are so many php files, I don't know were to put it.
  • 0

#4
Major Payne

Major Payne

    Retired Staff

  • Retired Staff
  • 5,307 posts
Guess I'm a little lost then. Not using WordPress makes it hard for me to visualize the problem of placement. Would you want it as a link on all blog pages so people would have a choice to get the weather or to display on all blog pages in its own little box?

Only responded to this thread as I'm always open to learning something and WordPress may be a future project for me.
  • 0

#5
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 33,101 posts
Hi Ron,

Well maybe if we think out loud, we can figure it out. :)

I want it on this page:
http://www.pieter-ar...log/?page_id=33

Below the links I want to add something like:

Or you can come visit me.
Then below or beside each other (have to see what looks best) a Google map of the area where I live and the weather forecast.

The editor fo those pages allows you to write all sorts of things, but only accepts html or bbcode. It just prints the php code.
  • 0

#6
Ryan

Ryan

    Member 4k

  • Member
  • PipPipPipPipPipPipPip
  • 4,867 posts
Hey Ron, Metallica. Hope you don't mind me jumping in, but I figured I could be of some use since I know a bit about WordPress.

There are a couple ways to get that code to run on a page. The first is probably the best, since it involves using a plugin, Exec-PHP, to allow PHP to be used in posts, pages, and widgets.

The other method would be editing the page.php template to only run the code if the page being displayed is a certain page. The downside to this is that if you ever want to change themes, you would have to make the change in the template again.

-Ryan
  • 0

#7
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 33,101 posts
Thanks Ryan, :)

I'll try that when I get home.
And keep you posted of course.
  • 0

#8
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 33,101 posts
This didn't work. Added to page.php

if($page_ID==33) {
	echo 'Or you can come and visit me.';
	$mfgetweather->get_weather('nlxx0015', 'Rotterdam', 'icon,temp,high,low,dayforecast');
 }

Going to try the plugin now.
  • 0

#9
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 33,101 posts
Geez I feel inadequate;

Using the exec-php generates this error:

Fatal error: Call to a member function get_weather() on a non-object in /home/pieter/public_html/wordpressblog/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 7
  • 0

#10
Michael

Michael

    Retired Staff

  • Retired Staff
  • 1,869 posts
Problem is that anything you put into eval has to be a fully self contained bit of code. And $mfgetweather which is supposed to be a instance of some class has not been initialized. So you going to need to add something like
$mfgetweather = new WhatEverItIsCalled($some,$args,$here,$maybe);
in to you little snippet. Sorry :) too lazy to download the Weather plugin to check the exact code.

How does the code in post #8 not work? Does it show any error or just do nothing?

Edited by Michael, 16 September 2008 - 06:42 PM.

  • 0

#11
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 33,101 posts

How does the code in post #8 not work? Does it show any error or just do nothing?


It does nothing at all. It just gets skipped as if the condition is not met.


Tried:
<?php 
$mfgetweather = new get_weather('nlxx0015', 'Rotterdam', 'icon,temp,high,low,dayforecast');
$mfgetweather->get_weather('nlxx0015', 'Rotterdam', 'icon,temp,high,low,dayforecast'); 
?>

Result:
Fatal error: Class 'get_weather' not found in /home/pieter/public_html/wordpressblog/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 10

Would I need to point out the relative path? I don't think so because MFGetweather is an active plugin, but I thought I'd ask anyway.
  • 0

#12
Michael

Michael

    Retired Staff

  • Retired Staff
  • 1,869 posts
Ok I downloaded the plugin - can't test it as I don't have word press. But I think this would work.
<?php
$mfgetweather = new MFGetweather();
$mfgetweather->get_weather('nlxx0015', 'Rotterdam', 'icon,temp,high,low,dayforecast');
?>
If not try something like this.
<?php
include('where_ever_you_put_it/mfgetweather.php');
$mfgetweather = new MFGetweather();
$mfgetweather->get_weather('nlxx0015', 'Rotterdam', 'icon,temp,high,low,dayforecast');
?>

The problem here is eval runs in its own little environment so I don't know how much luck you going to have calling a wordpress plugin.

Or if you want to go back the the other idea try.
if($_GET['page_id']=='33') {
	echo 'Or you can come and visit me.';
	$mfgetweather->get_weather('nlxx0015', 'Rotterdam', 'icon,temp,high,low,dayforecast');
}

Edited by Michael, 16 September 2008 - 11:01 PM.

  • 0

#13
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 33,101 posts
I'll try those ideas when I get home Michael. Thanks. :)
  • 0

#14
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 33,101 posts
Your first idea worked Michael. :)

http://www.pieter-ar...log/?page_id=33
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP