Function to hide ads and function to show author

Posted in: Newspaper
Post count: 76

Hey Alin! Thanks, now that I’ve found the right file and I’ve added the codes as outlined above, I’m running into other issues. I followed the steps to add the code based on the field names I made (I created three hide_inline_ads, hide_top_ad and hide_bottom_ad) so it would have been easier for me to identify which is which. I placed in the code like you can see in this image:
Ad Codes added

But for some reason now when I check the posts themselves on the frontend nothing shows up (I’m currently testing this on my staging site). Any ideas what’s wrong in the code?

Here’s how the front end looks when you visit a post: Blank Post Screen now

And this is the ACF fields added: ACF code added

Post count: 76

Can anyone please help me figure out what’s wrong and why it’s not working?

Post count: 51

Hi guys,

i was looking for the solution to this problem: i perfectly managed to hide ads IN the article (thanks to this discussion), but i could not be able to hide them in the top header (which is outside the article block) and in the sidebar.

I tried to edit the header-style-3.php (which is the style i got set from the newsmag menu i guess) file but no results on that, the ad stills there and this is the code i insered in this file:

<div class="span8 td-header-style-1">
		<?php
			//show the header ad spot
			if (!get_field('hide_ad')) {
				echo td_global_blocks::get_instance('td_ad_box')->render(array('spot_id' => 'header'));
			}
		?>	
	</div>

Am i doing something wrong? And what should i edit for the sidebar?

My website post page where i’m trying to hide them is this one: MyTechnology

  • This reply was modified 10 years by reloaded.
Post count: 7909

Hi,

If you add your condition here in td_block_ad_box.php you should be able to hide all ads on specific post – http://screencast.com/t/rjtt8VdJJ
For newsmag theme it is the same file.

Thanks!

Post count: 51

Hi Alin,
thanks for answering, can you be a little more specific? I’m not that good in coding and i get syntax errors.

Also, should i use only this file to hide all of the ads then? or it is this file + the td_module_single_base.php file?

Thanks again!

Paolo

Post count: 51

I’m still trying to paste the code in the file you suggested, even just this part of the one above:

//show the header ad spot
			if (!get_field('hide_ad')) {
				echo td_global_blocks::get_instance('td_ad_box')->render(array('spot_id' => 'header'));
			}

but or i get syntax error or simply nothing happens and ads keeps showing

  • This reply was modified 10 years by reloaded.
Post count: 76

Hey reloaded, did you set specific ones for each ad. For example if you’re targeting the top ad, you want the code to say hide_top_ad

Here’s the entire lines of code for the full ad section in the file found in the wp-booster folder:

/* ----------------------------------------------------------------------------
ad support on content
*/

//read the current ad settings
$tds_inline_ad_paragraph = td_util::get_option('tds_inline_ad_paragraph');
$tds_inline_ad_align = td_util::get_option('tds_inline_ad_align');

//add the inline ad
if (td_util::is_ad_spot_enabled('content_inline') and is_single() and !get_field('hide_inline_ads')) {

if (empty($tds_inline_ad_paragraph)) {
$tds_inline_ad_paragraph = 0;
}

$cnt = 0;
$content_buffer = ''; // we replace the content with this buffer at the end

$content_parts = preg_split('/(<p.*>)/U', $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

$p_open_tag_count = 0; // count how many <p> tags we have added to the buffer
foreach ($content_parts as $content_part_index => $content_part_value) {
if (!empty($content_part_value)) {

// Show the ad ONLY IF THE CURRENT PART IS A <p> opening tag and before the <p> -> so we will have <p>content</p> ~ad~ <p>content</p>
// and prevent cases like <p> ~ad~ content</p>
if (preg_match('/(<p.*>)/U', $content_part_value) === 1) {
if ($tds_inline_ad_paragraph == $p_open_tag_count) {
switch ($tds_inline_ad_align) {
case 'left':
$content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'left'));
break;

case 'right':
$content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'right'));
break;

default:
$content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline'));
break;
}
}
$p_open_tag_count ++;
}
$content_buffer .= $content_part_value;
$cnt++;
}
}
$content = $content_buffer;
}

//add the top ad
if (td_util::is_ad_spot_enabled('content_top') and is_single() and !get_field('hide_top_ad')) {
$content = td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_top')) . $content;
}

//add bottom ad
if (td_util::is_ad_spot_enabled('content_bottom') and is_single() and !get_field('hide_bottom_ad')) {
$content = $content . td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_bottom'));
}

return $content;
}

You can see each of the different ad placements (top, inline and bottom) have their own name and respective field in ACF.

Post count: 51

Hi shae101s,
as i said previously, i already managed to hide the 3 “in post” ads… but what i’m trying to hide as well are sidebar and top header ads which are located outside of the post’s loop. If a specific blog post is not compliant with adsense policy i guess that all of the ads must be deactivated and not only those inside the article by themself.

Post count: 51

ok, i was able to hide the top header ad by modifying ads.php file in the “header” folder and the code i used is this one:

<div class="td-header-ad-wrap <?php echo $td_no_ad_class;?>">
    <?php
			//show the header ad spot
			if (!get_field('hide_ad_all')) {
				echo td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'header'));
			}
		?>	
</div>

But i really can’t understand what to do for the sidebar.

I think the code to be used should be something like this:

//show the sidebar ad spot
			if (!get_field('hide_ad_all')) {
				echo td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'custom_ad_1'));
			}

where “hide_ad_all” is a custom field i just created only for top header and sidebar ads and because i’m using custom ad 1 in the articles’s sidebar but i don’t understand where or in which file to paste this code. I tried with sidebar.php, td_block_ad_box.php and others but with no results.

if someone has any idea…

  • This reply was modified 10 years by reloaded.
Post count: 7909

Hi,


@reloaded
I cannot provide a solution only for sidebar. If you add the condition in td_block_ad_box.php all the ads will be blocked in a post when you have the custom field enabled(header, article ads, sidebar).

Thanks!

Post count: 51

Hi Alin,
i have to ask you sorry because when i looked at your screencast i didn’t realized you also posted the hide_ad code.

By the way, now i did it exactly as you posted and i have this code in the td_block_ad_box.php file:

$buffy = '';
		if (!get_field('hide_ad')) {
        $buffy .= '<div class="td-a-rec td-a-rec-id-' . $spot_id . $align . ' '
            . ((!empty($ad_array['disable_m'])) ? ' td-rec-hide-on-m' : '')
            . ((!empty($ad_array['disable_tp'])) ? ' td-rec-hide-on-tp' : '')
            . ((!empty($ad_array['disable_p'])) ? ' td-rec-hide-on-p' : '')
            . '">';
        $buffy .= do_shortcode(stripslashes($ad_array['ad_code']));
        $buffy .= '</div>';

		}
        //print_r($ad_array);
        return $buffy;

    }
}

But this does not make my ads to desappear (my custom ad field is named the same)… they are still there (all of them).

  • This reply was modified 10 years by reloaded.
Viewing 11 posts - 26 through 36 (of 36 total)
The forum ‘Newspaper’ is closed to new topics and replies.