내용보기 치환할 때, 모바일과 모바일이 아닌 것 다르게 보이기
본문
글작성할 때
{광고}라고 치면, '내용보기' 화면에서 광고가 출력되는데,
모바일과 모바일이 아닐 때, 그 내용이 다르게 출력되도록 하고 싶습니다.
즉, 광고가 표시되는데
모바일일때는 (소스1) 의 내용이 표시
모바일이 아닐때는 (소스2) 의 내용이 표시
지금은 두가지가 모두 표시가 되는데, 틀린 부분이 무엇일까요?
<?php
$content = get_view_thumbnail($view['content']);
$content = str_replace('{광고}', '
<?php if(!G5_IS_MOBILE) { ?>
<ins class="adsbygoogle"
style="display:block; margin:15px 0;"
data-ad-format="fluid"
data-ad-layout-key="-fc+5g+70-cl-1m"
data-ad-client="ca-pub-8618685012773575"
data-ad-slot="8345951427"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<?php } ?>
<?php if(G5_IS_MOBILE) { ?>
<ins class="adsbygoogle"
style="display:block; text-align:center; margin:15px 0;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="ca-pub-8618685012773575"
data-ad-slot="5305581469"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<?php } ?>
', $content);
echo $content;
?>
답변 2
<?php
$content = get_view_thumbnail($view['content']);
if(!G5_IS_MOBILE) {
$content = str_replace('{광고}', '<ins class="adsbygoogle"
style="display:block; margin:15px 0;"
data-ad-format="fluid"
data-ad-layout-key="-fc+5g+70-cl-1m"
data-ad-client="ca-pub-8618685012773575"
data-ad-slot="8345951427"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>',$content);
}else{
$content = str_replace('{광고}', '<ins class="adsbygoogle"
style="display:block; text-align:center; margin:15px 0;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="ca-pub-8618685012773575"
data-ad-slot="5305581469"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>',$content);
}
echo $content;
?>
이런식으로 순서를 바꾸시면 됩니다.
!-->
<?php
$ad = '';
if(!G5_IS_MOBILE) {
$ad = <<<HEREDOC
<ins class="adsbygoogle"
style="display:block; margin:15px 0;"
data-ad-format="fluid"
data-ad-layout-key="-fc+5g+70-cl-1m"
data-ad-client="ca-pub-8618685012773575"
data-ad-slot="8345951427"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
HEREDOC;
} else {
$ad = <<<HEREDOC
<ins class="adsbygoogle"
style="display:block; text-align:center; margin:15px 0;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="ca-pub-8618685012773575"
data-ad-slot="5305581469"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
HEREDOC;
}
$content = str_replace('{광고}', $ad, $content);
echo $content;
?>
답변을 작성하시기 전에 로그인 해주세요.