Forums

Calling a function from a php include in my Post (7 posts)

  1. 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

  2. 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?

  3. 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.

  4. Kafkaesqui
    Moderator
    Posted 3 years ago #

    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().

  5. 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">

  6. <?php the_title();?> is Rogue Anti-Spyware more
  7. <?php the_title();?> is embedded by a Trojan more
  8. <?php the_title();?> issues fake security warnings more
  9. <?php the_title();?> may come bundled with other Malware more
  10. <?php the_title();?> may recreate, repair and update itself more
  11. </div>'

  • Kafkaesqui
    Moderator
    Posted 3 years ago #

    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.

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags