green_globe
June 14th, 2006, 04:36 AM
Hi;
this is my first post here,
I am learning php, and new to php.
it has been couple days now that I have been working on a script and got lots of help as well, but now going crazy over this and stuck and need help, hopfully get some help here to make it work, I am greatful for that.
I used a word count script to make it work for something that I want to have for my blog using wp,
I want to add a small picture into every post ( whenever there is a post) after certain number of words. ( the pic should be inserted right after the counting finnished, not at the end of the post) I was told that it is a good way to start by getting the steaming text and then count it and then insert the pic into it,
the script works,
it does its job by posting the article with picutes in it,
and so the blog by posting the article,
this is the problem, two posts,
on top the actual post and below it the duplicate one with picture in it( without title).
how can I prevent that.
I don't want to prevent wp to do its job, I want to work around the script to make it insert pic into the post.
the script was a word count and as you can see at the end it will print the total number of words in the post, which I am not interested but for now it is there.
here is the scripts:
<?php
function add_pic()
{
global $wpdb;
$count = $oldcount = $totalcount = $tally = 0;
$printme = "";
$filepath = 'images/';
$file="pic_1.gif";
$now = gmdate("Y-m-d H:i:s",time());
$words = $wpdb->get_results("SELECT post_content
FROM $wpdb->posts WHERE post_status = 'publish'
AND post_date < '$now'");
if ($words)
{
foreach ($words as $word)
{
$post = strip_tags($word->post_content);
$post = preg_replace( '/ +/', " ", $post);
$post = explode(' ', $post);
$count = count($post);
for($x=0; $x < $count; $x++)
{
$tally++;
$printme .= $post[$x] . " ";
if($tally == 20 )
{
$printme .= "\n" .'<img src="'.$filepath.$file . '" />';
$tally = 0;
}
}
$totalcount += $count;
}
} else
{
$totalcount=0;
}
echo $printme;
echo number_format($totalcount);
}
?>
appreciate your help.
this is my first post here,
I am learning php, and new to php.
it has been couple days now that I have been working on a script and got lots of help as well, but now going crazy over this and stuck and need help, hopfully get some help here to make it work, I am greatful for that.
I used a word count script to make it work for something that I want to have for my blog using wp,
I want to add a small picture into every post ( whenever there is a post) after certain number of words. ( the pic should be inserted right after the counting finnished, not at the end of the post) I was told that it is a good way to start by getting the steaming text and then count it and then insert the pic into it,
the script works,
it does its job by posting the article with picutes in it,
and so the blog by posting the article,
this is the problem, two posts,
on top the actual post and below it the duplicate one with picture in it( without title).
how can I prevent that.
I don't want to prevent wp to do its job, I want to work around the script to make it insert pic into the post.
the script was a word count and as you can see at the end it will print the total number of words in the post, which I am not interested but for now it is there.
here is the scripts:
<?php
function add_pic()
{
global $wpdb;
$count = $oldcount = $totalcount = $tally = 0;
$printme = "";
$filepath = 'images/';
$file="pic_1.gif";
$now = gmdate("Y-m-d H:i:s",time());
$words = $wpdb->get_results("SELECT post_content
FROM $wpdb->posts WHERE post_status = 'publish'
AND post_date < '$now'");
if ($words)
{
foreach ($words as $word)
{
$post = strip_tags($word->post_content);
$post = preg_replace( '/ +/', " ", $post);
$post = explode(' ', $post);
$count = count($post);
for($x=0; $x < $count; $x++)
{
$tally++;
$printme .= $post[$x] . " ";
if($tally == 20 )
{
$printme .= "\n" .'<img src="'.$filepath.$file . '" />';
$tally = 0;
}
}
$totalcount += $count;
}
} else
{
$totalcount=0;
}
echo $printme;
echo number_format($totalcount);
}
?>
appreciate your help.