Wordpress plugin or code that inserts into post?

Status
Not open for further replies.

cpd

New member
Nov 1, 2006
61
0
0
I'm trying to find a wordpress plugin that will automaticall insert text into the middle of a post, or figure out the way to code it.

I'd like to throw some affiliate text links in the middle of an article, something like:

blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah
-----------------------------------
Additional Resources:
Find detailed user reviews here
-----------------------------------
blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah

Any ideas?
 


Short answer:

Depending on what ads you want to serve, you need to install something from THIS list.





Long answer:

There are several places you can edit to do this; Here's a way (I'm pretty sure) to do it on your own, although not very elegantly:

Go to your WP root folder and open post-template.php and look for:

Code:
function get_the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    global $id, $post, $more, $single, $withcomments, $page, $pages, $multipage, $numpages;
    global $preview;
    global $pagenow;
    $output = '';

    if ( !empty($post->post_password) ) { // if there's a password
        if ( stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password ) {    // and it doesn't match the cookie
            $output = get_the_password_form();
            return $output;
        }
    }

    if ( $more_file != '' )
        $file = $more_file;
    else
        $file = $pagenow; //$_SERVER['PHP_SELF'];

    if ( $page > count($pages) ) // if the requested page doesn't exist
        $page = count($pages); // give them the highest numbered page that DOES exist

    $content = $pages[$page-1];
    if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
        $content = explode($matches[0], $content, 2);
        if ( !empty($matches[1]) && !empty($more_link_text) )
            $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
    } else {
        $content = array($content);
    }
    if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
        $stripteaser = 1;
    $teaser = $content[0];
    if ( ($more) && ($stripteaser) )
        $teaser = '';
    $output .= $teaser;
    if ( count($content) > 1 ) {
        if ( $more ) {
            $output .= '<span id="more-'.$id.'"></span>'.$content[1];
        } else {
            $output = balanceTags($output);
            if ( ! empty($more_link_text) )
                $output .= ' <a href="'. get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>";
        }

    }
    if ( $preview ) // preview fix for javascript bug with foreign languages
        $output =    preg_replace('/\%u([0-9A-F]{4,4})/e',    "'&#'.base_convert('\\1',16,10).';'", $output);

    return $output;
}
just do a str_replace() to $output before you return it, adding the ad code after x number of chars (wherever you want them to be).
 
Status
Not open for further replies.