We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7869
    • 118 Posts
    I have a content div (green box) that contains the [*#content*] and another div called adsense. I want the ad to be placed 2 inches down on the page, AND have all the text to wrap around it. Is this possible to do with css (see pic)? I want the text to wrap around the top, right, and bottom of the ad. I set a top margin to lower the image 2 inches. Then I set it to float left, but this doesn’t allow the text to flow on the top of the image. Only the right and bottom.

    I could accomplish this by inserting and {{AdSense}} chunk into each [*#content*], but that defeats the purpose of keeping everything separate. I want to accomplish this at the template level.

    #content {width: 500px;border-style: solid;}

    #adsense {float: left; width: 60; height: 50px; padding: 10px; margin: 100px 15px 0 0; border: solid thin;}
      -Dorian
      • 29240
      • 8 Posts
      This is a really old topic but I made a snippet to do this exact same thing in case anyone is interested.
      I call it contentAdInjector
      <?php
      $where = 1; //insert chunk after # </p>
      $content = $modx->documentObject['content'];
      $content = explode('</p>', $content);
      for ($i = 0; $i<count($content); $i++){
      	if ($i == $where) {
      		echo $modx->getChunk('adsense1'); //insert your chunk here
      		}
      	echo $content[$i] . '</p>';
      	}
      ?>
      


      Use this snippet in place of [*conent*] and your chunk will show up after the paragraph you specify in $where.
        • 12027
        • 63 Posts
        Talltree, nice! Could this be modified to only insert the first paragraph of the main text of an article?

        I’m using Ditto to make a blog page, but introtext can have no pictures (drab blog page) so I’m looking for a way to also include the first <p>.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          <?php
          $content = $modx->documentObject['content'];
          $content = explode('</p>', $content);
          echo $content[0]; // insert the first paragraph
          echo $modx->getChunk('adsense1'); //insert your chunk here
          ?>
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 3749
            • 24,544 Posts
            Very slick, Susan. But won’t the first paragraph show twice unless the [*#content*] tag is left out of the template (and then you’d lose the rest of the paragraphs)?

            Bob
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Use this snippet in place of [*conent*] and your chunk will show up after the paragraph you specify in $where.
              Talltree, nice! Could this be modified to only insert the first paragraph of the main text of an article?
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 3749
                • 24,544 Posts
                Quote from: sottwell at Feb 14, 2008, 12:13 AM

                Use this snippet in place of [*conent*] and your chunk will show up after the paragraph you specify in $where.
                Talltree, nice! Could this be modified to only insert the first paragraph of the main text of an article?

                Argggg. . . I’m about 0 for 6 today. smiley

                I should have taken the day off.

                Bob
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I frequently have days like that. Fortunately for me I’m in a position where I can either just go back to bed or go for a long walk in the desert. I’m trying to cut down on the going out to get chocolate, though.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 12027
                    • 63 Posts
                    OK, so I could use the part above the getChunk to extract the first paragraph, and include the output after the Ditto call somehow?
                      • 10076
                      • 1,024 Posts
                      so is this meant to enable injection of google adsense? Should it be something like this:

                      <?php
                      $where = 1; //insert chunk after # </p>
                      $content = $modx->documentObject['content'];
                      $content = explode('</p>', $content);
                      for ($i = 0; $i<count($content); $i++){
                      	if ($i == $where) {
                      		echo $modx->getChunk('<script type="text/javascript"><!--
                      google_ad_client = "pub-xxxxxxxxxxxxxx";
                      /* test */
                      google_ad_slot = "xxxxxxxxx";
                      google_ad_width = 180;
                      google_ad_height = 150;
                      //-->
                      </script>
                      <script type="text/javascript"
                      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                      </script>'); 
                      		}
                      	echo $content[$i] . '</p>';
                      	}
                      ?>
                      


                      And should i just place a call to this snippet somewhere in my template? Or do I need to change more in this script?