Any PHP Guru online to help me with something please ?

IntensE

Power Member
Joined
Aug 19, 2008
Messages
771
Reaction score
661
I want to create the following:

I have a WP blog whatever.com and a post "Hello world 2011" for example.

So, I go to the blog, click the post and end up here: whatever.com/hello-world-2011

In this post I have an <a href= link >to the php file phpguru.php

Now when I click on the link it should open whatever.com/phpguru.php and in there I want to echo the post title.

So it should echo me: "Hello World 2011"

How can I do that ? I need it badly.
 
It's actually not that straightforward. You are trying to open a php file outside of the Wordpress system so it technically has no access to the_titile() function.

You could actually just create a post and install the wordpress plugin exec-php plugin which will let you insert php code right into your post content. Maybe that will give you the results you're looking for.

Outside of that the only way I can think to implement this would be to pass the referring URL into your phpguru.php file, parse the post title out of the URL, then echo out the string.
 
You could actually just create a post and install the wordpress plugin exec-php plugin which will let you insert php code right into your post content. Maybe that will give you the results you're looking for.

As above. If you install exec-php plugin, I'll help you with the coding.
 
would be to pass the referring URL into your phpguru.php file, parse the post title out of the URL, then echo out the string.

THIS ! is what i want / need. how to do it ?
Abstroose can you help on this one please ?
 
Is the format of your permalinks exactly like this: yoursite.com/hello-world-2011

Or do you have categories?
 
Link to the following URL from one of your posts and tell me if it works:

Code:
http://www.nulbur.com/abc.php
 
Good. It's a little less reliable than passing the variable from the blog post, since if you change the permalink structure or click the link from your homepage, it won't work.. but other than that it does the job.

PHP:
<?php
$string = $_SERVER["HTTP_REFERER"];
$s = explode("/",$string);
$title = $s[3];
$title = str_replace("-", " ", $title);
echo $title;
?>
 
PHP guys who know more than me...

Why not just link to "whatever.com/phpguru.php?postid=<?php echo $post->ID; ?>" ?

The on the next page:
<?php echo get_the_title($_GET['postid'); ?>
 
cause that looks ugly, and php geeks tend to have clean codes :P

Abstroose, you are the man ! will send you a beer, thanks a lot !
 
sorry about my response, skim read the question and responded without reading this was external to wp :)
 
one more quick question, how can i make the letters upper case ?

it prints: hello world 2011, would love Hello World 2011
 
Hello, Your solution is fine but...
It loses case sensitive and few other things. If posttitle will be long than you will lose some words or letters.
I think you should use build in PHP and WP functions for this task.

Code mentioned below SHOULD* give you always correct post title.
PHP:
<?php
require_once( '../wordpress_install_path/wp-load.php' );
get_header();
$referer = pathinfo(wp_get_referer());
$slug = $referer['basename'];

$query = new WP_Query('pagename='.$slug);
while ($query->have_posts() ) : $query->the_post();
	the_title();
endwhile;
?>

SHOULD*- i havn't tested it.

Good. It's a little less reliable than passing the variable from the blog post, since if you change the permalink structure or click the link from your homepage, it won't work.. but other than that it does the job.

PHP:
<?php
$string = $_SERVER["HTTP_REFERER"];
$s = explode("/",$string);
$title = $s[3];
$title = str_replace("-", " ", $title);
echo $title;
?>
 
nvm figured it out:
$title = ucwords(strtolower($title));
 
Thanks guys for the help, +4 rep to both of you.
 
Back
Top