*

David Beaudoin

  • ****
  • 242 posts
  • https://abrutis.net
adsense and blog ?
« on: April 06, 2021, 04:30:48 PM »
hello, i am trying to embed adsense javascript code in php but it doesn't work.

Someone to direct me please?


Quote
​<?php
  $blog_id = Params::getParam('blogId');
  $blog = ModelBLG::newInstance()->getBlogDetail($blog_id);
  $author = ModelBLG::newInstance()->getAuthor($blog['fk_i_user_id']);
  $comments = ModelBLG::newInstance()->getComments($blog_id, 1);
  ModelBLG::newInstance()->updateBlogViews($blog_id);
?>


<script data-ad-client="ca-pub-5046117062556130" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

<?php


<div id="blg-body" class="blg-theme-<?php echo osc_current_web_theme(); ?>">
  <div id="blg-main" class="blg-content">
    <h1><?php echo blg_get_title($blog); ?></h1>

    <?php if(blg_get_subtitle($blog) <> '') { ?>
      <h2><?php echo blg_get_subtitle($blog); ?></h2>
    <?php } ?>

    <div class="blg-details">
      <?php if($blog['i_category'] > 0) { ?>
        <?php $blog_cat = ModelBLG::newInstance()->getCategoryDetail($blog['i_category']); ?>
        <div class="blg-detail-entry blg-detail-cat" <?php if($blog_cat['s_color'] <> '') { ?>style="background:<?php echo $blog_cat['s_color']; ?>;"<?php } ?>><?php echo blg_get_cat_name($blog_cat); ?></div>
      <?php } else { ?>
        <div class="blg-detail-entry blg-detail-cat"><?php _e('Uncategorized', 'blog'); ?></div>
      <?php } ?>

      <div class="blg-detail-entry"><?php echo date('j. M Y', strtotime($blog['dt_pub_date'])); ?></div>
      <div class="blg-detail-entry"><?php echo sprintf(__('%d views', 'blog'), $blog['i_view']); ?></div>
    </div>
 
 

    <div class="blg-content-text">
      <div class="blg-primary-img">
          <img src="<?php echo blg_img_link($blog['s_image']); ?>" alt="<?php echo osc_esc_html(blg_get_title($blog)); ?>" data-src="<?php echo blg_img_link($blog['s_image']); ?>"/>
      </div>

      <div class="blg-raw-text">
        <?php
          if(!blg_is_premium($blog)) {
            echo blg_get_description($blog);
          } else {
            echo osc_highlight(blg_get_description($blog), 800);
          }
        ?>
      </div>

      <?php if(blg_is_premium($blog)) { ?>
        <div class="blg-premium-cover"></div>
      <?php } ?>
    </div>

    <?php require 'premium.php'; ?>


    <?php if(blg_param('comment_enabled') == 1) { ?>
      <div class="blg-comments">
        <h2><?php _e('Comments', 'blog'); ?></h2>

        <?php if(count($comments) > 0) { ?>
          <?php $j = 0; ?>
          <?php foreach($comments as $c) { ?>
            <?php
              $j++;
              $cuser = User::newInstance()->findByPrimaryKey($c['fk_i_os_user_id']);
              $cauthor = ModelBLG::newInstance()->getUserByOsclassId($c['fk_i_os_user_id']);

              if(!$cauthor) {
                $is_author = false;
              } else {
                $is_author = true;
              }
            ?>


            <div class="blg-row<?php if($j == 1) { ?> blg-comment-first<?php } ?>">
              <div class="blg-comment-img">
                <?php
                  $cimg = '';

                  if($is_author) {
                    $cname = $cauthor['s_name'];
                    $cimg = blg_user_img($cauthor['s_image']);
                  } else {
                    $cname = (@$cuser['s_name'] <> '' ? $cuser['s_name'] : __('Anonymous', 'blog'));

                    if(function_exists('profile_picture_show')) {
                      if($c['fk_i_os_user_id'] > 0) {
                        $cimg = profile_picture_show(null, 'item', 200, null, $c['fk_i_os_user_id']);
                      }
                    }
                  }

                  if($cimg == '') {
                    $cimg = osc_base_url() . 'oc-content/plugins/blog/img/user/user-default.png';
                  }
                ?>

                <img src="<?php echo $cimg; ?>" alt="<?php echo osc_esc_html($cname); ?>" />
              </div>

              <div class="blg-comment-text">
                <div class="blg-comment-top">
                  <span class="blg-comment-user">
                    <?php if($is_author && @$cauthor['pk_i_id'] > 0) { ?>
                      <a href="<?php echo osc_route_url('blg-author', array('authorSlug' => osc_sanitizeString(blg_slug($cauthor['s_name'])), 'authorId' => $cauthor['pk_i_id'])); ?>" class="blg-comment-author-link"><?php echo $cname; ?></a>
                    <?php } else { ?>
                      <?php echo $cname; ?>
                    <?php } ?>
                  </span>

                  <span class="blg-comment-del"><?php _e('on', 'blog'); ?></span>
                  <span class="blg-comment-date"><?php echo date('j. M Y', strtotime($c['dt_pub_date'])); ?></span>
                </div>

                <div class="blg-comment-bot"><?php echo strip_tags($c['s_comment'], '<br>'); ?></div>
              </div>
            </div>
          <?php } ?>
        <?php } else { ?>
          <div class="blg-row blg-empty"><?php _e('No comments has been added on this post', 'blog'); ?></div>
        <?php } ?>
      </div>

      <div class="blg-new-comment">
        <h3><?php _e('Add new comment', 'blog'); ?></h3>

        <?php if(!osc_is_web_user_logged_in()) { ?>
          <div class="blg-row blg-not-logged"><?php _e('You must be logged in to add new comment', 'blog'); ?>. <a href="<?php echo osc_user_login_url(); ?>"><?php _e('Log in', 'blog'); ?></a></div>

        <?php } else { ?>
          <form class="nocsrf" method="POST" name="blg_new_comment" action="<?php echo osc_route_url('blg-action', array('blgPage' => 'comment')); ?>">
            <input type="hidden" name="fk_i_blog_id" value="<?php echo $blog_id; ?>" />

            <div class="blg-row">
              <label for="s_name"><?php _e('Your name', 'blog'); ?></label>
              <input type="text" name="s_name" id="s_name" value="<?php echo osc_esc_html(osc_logged_user_name()); ?>" readonly required/>
            </div>

            <div class="blg-row">
              <label for="s_comment"><?php _e('Comment', 'blog'); ?></label>
              <textarea name="s_comment" id="s_comment" required></textarea>
            </div>

            <button class="blg-btn blg-btn-primary" type="submit" title="<?php echo osc_esc_html(__('Submit', 'blog')); ?>"><i class="fa fa-check"></i> <?php echo osc_esc_html(__('Submit', 'blog')); ?></button>
          </form>
        <?php } ?>
      </div>
    <?php } ?>
  </div>

  <?php require_once 'sidebar.php'; ?>
</div>

Regards,

David
Regards,
David
0640404083

*

MB Themes

Re: adsense and blog ?
« Reply #1 on: April 06, 2021, 04:45:10 PM »
@David
I would put adsense into blg-body div content or deeper
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

David Beaudoin

  • ****
  • 242 posts
  • https://abrutis.net
Re: adsense and blog ?
« Reply #2 on: April 06, 2021, 04:59:56 PM »
It's true but that doesn't change the problem...

It was to do a test integration of the code but obviously it does not work...
Regards,
David
0640404083

*

David Beaudoin

  • ****
  • 242 posts
  • https://abrutis.net
Re: adsense and blog ?
« Reply #3 on: April 06, 2021, 05:02:14 PM »
@David
I would put adsense into blg-body div content or deeper

I don't even know where is what you told me
Regards,
David
0640404083

*

David Beaudoin

  • ****
  • 242 posts
  • https://abrutis.net
Re: adsense and blog ?
« Reply #4 on: April 06, 2021, 05:12:03 PM »
I integrated it into blg-body and here is the result...
Regards,
David
0640404083

*

MB Themes

Re: adsense and blog ?
« Reply #5 on: April 06, 2021, 05:22:03 PM »
You did something wrong, as you see results
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

David Beaudoin

  • ****
  • 242 posts
  • https://abrutis.net
Re: adsense and blog ?
« Reply #6 on: April 06, 2021, 05:32:06 PM »
I integrated the code the same way I showed you in my first post and it always gives me that no matter where I put it.

this is the way to implement the code which is not good and i would like to know how to implement it correctly
Regards,
David
0640404083

*

MB Themes

Re: adsense and blog ?
« Reply #7 on: April 06, 2021, 05:49:15 PM »
That should be written on google docs
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

David Beaudoin

  • ****
  • 242 posts
  • https://abrutis.net
Re: adsense and blog ?
« Reply #8 on: April 06, 2021, 05:55:12 PM »
No he only talks about HTML not PHP and for the rest when he is in CMS he refers to the author of the CMS yes, that's what I do ...
Regards,
David
0640404083

*

MB Themes

Re: adsense and blog ?
« Reply #9 on: April 06, 2021, 07:17:13 PM »
Php is enclosed in php tags, rest is html.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

David Beaudoin

  • ****
  • 242 posts
  • https://abrutis.net
Re: adsense and blog ?
« Reply #10 on: April 07, 2021, 09:12:43 AM »
Until then it doesn't work, it always gives what I have on the screenshot. However, I inserted my code normally as in my 1st message ...
Regards,
David
0640404083

*

MB Themes

Re: adsense and blog ?
« Reply #11 on: April 07, 2021, 09:18:53 AM »
@David
Well basically your screenshot looks like it generates error and stops execution at start.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

David Beaudoin

  • ****
  • 242 posts
  • https://abrutis.net
Re: adsense and blog ?
« Reply #12 on: April 07, 2021, 09:37:21 AM »
But don't you have any idea what could be wrong with my code insertion?
Regards,
David
0640404083

*

MB Themes

Re: adsense and blog ?
« Reply #13 on: April 07, 2021, 09:39:34 AM »
@David
Well, probably because of that <?php tag after adsense code
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

David Beaudoin

  • ****
  • 242 posts
  • https://abrutis.net
Re: adsense and blog ?
« Reply #14 on: April 07, 2021, 09:41:16 AM »
But I have to reopen PHP, right?
Regards,
David
0640404083