1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

need help to make a php code works

Discussion in 'PHP' started by greenworld, Jun 9, 2006.

  1. greenworld

    greenworld Peon

    Messages:
    65
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #21
    thank you clancey ;
    you did help me a lot,
    I will work on it to see how I can solve the problem.

    if anyone can figure it out how to stop this double post, please help me out,
    I am really greatful,

    thanks again
     
    greenworld, Jun 13, 2006 IP
  2. jnestor

    jnestor Peon

    Messages:
    133
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #22
    You need to look at the code that actually outputs the posts.

    look in /wp-content/themes/{name of your theme}/
    I think index.php is the main page.
    The single post page is i think single.php

    The word press docs has lots of info about modifying your theme that you should check out. I think the "normal" output of the post is done with the_content() function but I could be wrong.
     
    jnestor, Jun 14, 2006 IP
  3. greenworld

    greenworld Peon

    Messages:
    65
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #23
    thank you jnestor for reply;

    I have already looked into that,
    yes that is a function called " the_content'
    here is the code:
    <?php the_content('Read the rest of this entry &raquo;'); ?>

    but I have taken that out, which I know that I should not mess with other thing, but the result is, the actual post of the blog does not appear as expected, and post with pic in it apear as result of script, but without title, and it works in funny way when there are more posts.

    I am still working around it.

    is it possible to use the "the_content " function instead of pulling data from $wpdb ?
    just a thought,



    thanks.
     
    greenworld, Jun 14, 2006 IP
  4. jnestor

    jnestor Peon

    Messages:
    133
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #24
    I haven't hacked around with WP too much. You might be able to modify the actual the_content function to make it insert the pics but that's sort of not in the spirit of WP and their templating system. In other words when they make fixes and upgrades you'd need to re-apply your changes.

    If you're just missing the title you can use the "the_title()" tag. As far as I can tell there's no way at the post content itself using the tags. In other words you have to get it out of the db. You'll need to be a bit careful since there are some other things that "the_content()" does. Like stopping at the "<!--more-->" tag in the post. But if you avoid using that you should be ok.
     
    jnestor, Jun 14, 2006 IP
  5. greenworld

    greenworld Peon

    Messages:
    65
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #25
    thank you again for your reply,

    I am not very good at php, so I can not go into working with "the content" funciton.

    the first thing is to find out where this loop doing the repeated post,
    and stop it, maybe using another condition.

    I am going nuts here to find where the loop is doing wrong,

    anyone is good at loop who can help me out?

    as I mentioned above, every time you post, it will repeat the previous post as well,
    for exp: the second post you have 4 post( 2 post of every post), the third post you have three posts of every post (9 posts), the 7th post, you have 7 post of every post, and so on..

    I wonder if the following lines of code is the problem:
     
    
     for($x=0; $x < $count; $x++)       {
     $tally++;                
    $printme .= $post[$x];
    
    PHP:
    I don't understand the last line of code completly,
    does the [$x] represent the post no? ( the index key of $post in the array)

    every time there is a post, the $x value will be equal to 1 ,
    does ever the $x value goes beyond value of 1?

    I see it that the $x value is always 1 as long as there is more than one word in the post.
    so the $post[$x] becomes:
    $post[1];
    so is this the first post?

    that's why I don't understand it,
    in this way I can not see it goes to second post.

    Have I approched it right?

    thanks alot for any help
     
    greenworld, Jun 14, 2006 IP
  6. jnestor

    jnestor Peon

    Messages:
    133
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #26
    You'd have to post the whole script as it exists at this point and how/where you're calling it.

    I think the problem lies in that you need to move the line:
    $printme = "";
    inside the foreach loop but outside the for loop.

    The section of code you poste takes each word in the post and adds it to a string $printme. $x is index variable of the for loop so it ranges from 0 to the number of words in the post.
     
    jnestor, Jun 15, 2006 IP
  7. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #27
    The problem with the articles getting posted multiple times stems from the fact that the function you hacked is not the one which displays articles. It is the function with counts how many words there are in an article.

    In order to insert picture code every 100 words, it was necessary to count through all the words in the post and every one hundredth word insert a new piece of code.

    We did that by saving each individual word in the post into the $printme variable and at every 100th word, adding the HTML markup for the picture. The $printme .= $post[$x] gathers together the post, one word at a time, into the variable $printme. This means that $post[1] is the first word in an individual post.

    When the post is complete, the system displays the edited post.

    To know what to comment out in the original code look for calls to the function mdv_post_word_count()

    You should be able to see where the title is being echoed to the screen and where the content of the post is being echoed to the screen. Comment out the lines of code which echo out the psot. Remember, you hacked mdv_post_word_count() to display the full post along with the word count.

    We have been operating under the presumption that mdv_post_word_count() returned the word count for an individual post.
    If that is not true, then you may have chosen the wrong bit of code to rewrite. As mentioned at one point in this thread, it would be better to create a separate function to modify text. Then you just have to insert that function where the text is being printed out to the screen.

    jnestor is right in stating that hacking the cripts in this manner makes it harder to upgrade to newer versions of WP. However, mamking these changes and maintaining them in the future is going to teach you a little more about coding.
     
    clancey, Jun 15, 2006 IP