CMS솔루션마켓, 이온디 - 워드프레스, 라이믹스, 카페24, 그누보드, 엑셀

Contents Management System

1. 게시판 리스트의 경우

<!--구글 중간 광고-1-->
<block cond="$mobile && $module_info->spaceAd=='y'">
      <script>
         jQuery(function() {
            // 구글 900px
            var html1 = "<div style='padding-top:10px;clear:both;'><script async src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"><\/script>" +
               "<ins class=\"adsbygoogle\" style=\"display:inline-block;width:900px;height:120px\" data-ad-client=\"ca-pub-6354996705466866\" data-ad-slot=\"6057999515\"><\/ins>" +
               "<script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script><\/div>";
            // 구글반응형
            var html2 = "<script async src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"><\/script>"+
               "<ins class=\"adsbygoogle\" style=\"display:block\" data-ad-client=\"ca-pub-6354996705466866\" data-ad-slot=\"9022145565\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins>"+
               "<script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script>";
            // 구글3반응형 ( 마찬가지 가려짐)
            var html3 = "<script async src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"><\/script>" +
                     "<ins class=\"adsbygoogle\" style=\"display:block\" data-ad-client=\"ca-pub-6354996705466866\" data-ad-slot=\"7824382451\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins>" +
                     "<script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script>";
            var cnt = 2*{$module_info->bnCnt}-1;
            jQuery('li.goodslist:eq('+cnt+')').after(html1);
            console.log( cnt );
            //01 = 2*(1)-1
            //23 = 2*(2)-1
            //45 = 2*(3)-1
            //67 = 2*(4)-1
            //89 = 2*(5)-1
         });
      </script>
</block>
                 <!--구글 중간 광고-2-->


2. 게시물 글 중간의 경우

// xe_content 본문 p 가운데 광고 삽입
jQuery(function ($) {
   var hi = '안녕!'
   var html = "<div style='padding-top:10px;clear:both;'><script async src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"><\/script>" +
      "<ins class=\"adsbygoogle\" style=\"display:inline-block;width:900px;height:120px\" data-ad-client=\"ca-pub-6354996705466866\" data-ad-slot=\"6057999515\"><\/ins>" +
      "<script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script><\/div>";
   var ad = "<ins class=\"adsbygoogle\" style=\"display:block\" data-ad-client=\"ca-pub-9367344643205650\" data-ad-slot=\"2590542126\"data-ad-format=\"auto\"><\/ins>" +
      "<script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script>";

   var p_cnt = $(".xe_content > p").length;
   var cnt = Math.ceil(p_cnt/2);
   console.log(cnt);
   $('.xe_content > p:eq('+cnt+')').after(ad);
});

참조 : https://javacpro.tistory.com/41 


http://blog.naver.com/PostView.nhn?blogId=jung_w_w&logNo=220522104426&parentCategoryNo=&categoryNo=18&viewDate=&isShowPopularPosts=true&from=search 


게시물이 .xe_content 안에 p 태그로 이뤄진다는 것을 착안해서,

.xe_content > p 의 갯수를 센 뒤에, 2로 나눠서,

게시물 가운데에 .after() 함수를 이용해서 구글 광고 코드를 띄움.

※ 이때, p 태그의 반이 소수점일 경우 올림처리함.

추천한 사람

 
댓글은 로그인 사용자만 작성 가능합니다. 로그인하기