0

当帖子标题中出现停用词时,我想从 Wordpress 主题中隐藏一个 div。

<?php if (in_category('10')) { ?>
<div id="adsense-top">the adsense code</div>
<?php }else { ?>
<?php } ?>
+
<div id="adsense-bottom">the adsense code</div> - this is manually inserted

基本上,当标题中出现某个单词时,我需要从帖子中删除两个 div。

4

1 回答 1

0

这是一个简单的方法来实现这一点Javascript

<script type="text/javascript">
   var title = document.title;         //title of the page is returned
   if(title.indexOf('stop') !== -1) {  //If not found, it will return -1
     document.getElementById('adsense-bottom').style.display = 'none';
   }
</script>

但是在php,你需要这样做

<?php if (in_category('10')) { ?>
<div id="adsense-top">the adsense code</div>
<?php }else { ?>
    <script type="text/javascript">
       var title = document.title;         
       if(title.indexOf('stop') !== -1) {  
         document.getElementById('adsense-bottom').style.display = 'none';
       }
    </script>
<?php } ?>

希望像这样你需要添加。我不确定这是不是正确的地方。

于 2013-08-10T12:48:11.810 回答