Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Wordpress blog question


  • Please log in to reply

#1
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 31,671 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
  • 31,671 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
  • 31,671 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
  • 31,671 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
  • 31,671 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
  • 31,671 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
  • 31,671 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
  • 31,671 posts
I'll try those ideas when I get home Michael. Thanks. :)
  • 0

#14
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 31,671 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