Insert graphic after paragraph 5

Discussion in 'PHP' started by lilac2, Jun 7, 2008.

  1. #1
    Hello

    I am trying to achieve this output:

    IF PARAGRAPH IS AFTER PARAGRAPH5
    // EXECUTE CODE

    Can it be done?

    Thanks
     
    lilac2, Jun 7, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    I'm guessing there is a clear divide between paragraphs, perhaps 2 "\n" occur or something similar?

    Explode by the divider, then use a loop and if the current loop is greater than 5, run extra code, e.g. echo an image.

    Dan

    P.s. be less vague next time, my answer my be completely wrong - but it's hard without much detail.
     
    Danltn, Jun 7, 2008 IP
  3. lilac2

    lilac2 Peon

    Messages:
    367
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    OK - I should add that this is for a WordPress blog and I know a bit of PHP but I'm no expert. When you say explode, divider, and loop, it baffles me.
     
    lilac2, Jun 7, 2008 IP
  4. lui2603

    lui2603 Peon

    Messages:
    729
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if your paragraphs are in an array or being taken from a database maybe:

    
    $paragraphs = array('p1','p2','p3','p4','p5'); //Array should contain your paragraphs
    for($i=0; $i<count($paragraphs); $i++){
     echo $paragraph[$i];
     if($i == 5){
      echo '<br /> -graphic code goes here';
     }
    }
    
    PHP:
     
    lui2603, Jun 7, 2008 IP
  5. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #5
    This is bascially what I'm saying above, (www.php.net/explode is just a way of getting a string into an array.) and lui has used a suitable loop for showing the text.

    Although always assign count($paragraphs) to a variable before looping, or it will be ran every loop.

    Dan

    p.s. and divider just means something that divides (i.e. goes in between) the paragraphs.
     
    Danltn, Jun 7, 2008 IP
  6. lilac2

    lilac2 Peon

    Messages:
    367
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I don't think WordPress stores paragraphs (I can't find the table). Does that mean it won't work?


    Thanks.
     
    lilac2, Jun 7, 2008 IP
  7. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #7
    No, you could write an extremely basic plugin, which would then have a hook added to the text, which could do this for you.

    Dan
     
    Danltn, Jun 7, 2008 IP
  8. lilac2

    lilac2 Peon

    Messages:
    367
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yeah I did it this way. It worked. Thanks. I have to generate the code by clicking a button for each post - but that also gives me more control over ad optimization so I think it's fine.
     
    lilac2, Jun 7, 2008 IP
  9. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #9
    Good to see it worked out for you.

    Dan
     
    Danltn, Jun 7, 2008 IP