trentpunker
Member
Posted 3 years ago #
Hi guys,
I'm pretty new to WP and PHP. What I'm trying to do is have this function <?php the_title();?> in my include which I have inserted into my post. I have used the runPHP plugin to allow me to add PHP to my posts so that part is working.
If anyone could give me a hard that would be great!
Cheers
KatGirl
Member
Posted 3 years ago #
my include
Huh? Can you elaborate, just a tad? Are you wanting to display code in a post? Or use it in a post?
trentpunker
Member
Posted 3 years ago #
What I want to happen is to have a separate php file which I’ll include into my posts.
In the php include file I want to display the post title which is <?php the_title();?>
So every time I include this file it will be the same information apart from the post title.
Let me know if it’s still not clear. Thanks so much.
The separate script file you're including would have to be 'WP-enabled' for it to use a WordPress function like the_title(). So make sure it first includes the wp-blog-header.php file (from your blog's root) before it does any WP-ish stuff.
Note: To avoid any conflicts, use include_once().
trentpunker
Member
Posted 3 years ago #
Thanks for that! I nearly have it. I have the include working but the <?php the_title();?> is calling the title of the first post in the index page and not the title of the current post. How can I force it to call the current "post title"?
This is roughly what I have:
'<?php
define('WP_USE_THEMES', false);
require('../../../wp-blog-header.php');
?>
<div class="postDownBox">
<div class="malbox"><?php the_title();?> malicious properties:
<ul class="malProperties">
<?php the_title();?> is Rogue Anti-Spyware more
<?php the_title();?> is embedded by a Trojan more
<?php the_title();?> issues fake security warnings more
<?php the_title();?> may come bundled with other Malware more
<?php the_title();?> may recreate, repair and update itself more
</div>'
Hmm...
The only thing I imagine *might* work is if you can pass the ID or postname of the current post to your script, like so:
include('script.php?p=10')
include('script.php?name=the-current-post')
It sort of adds a bit to your post composition efforts, but I can't think of another way to string the two components together.
trentpunker
Member
Posted 3 years ago #
I guess that will take out the ease of not touching it every post. Thanks anyway.
Any other ideas will be greatly appreciated. Cheers mate.