如果标题包含停止字,如何隐藏DIV


How to hide a DIV if title contain stop word

当文章标题中出现停止词时,我想从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。

这里有一个在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 } ?>

希望你需要添加这样的内容。我不确定这个地方是否合适。