最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Wordpress Portofolio Conditional Templating - functions php

programmeradmin3浏览0评论

I'm trying to load some code depending on which portfolio category i am , but cant seem to get it quite right... I've read that portfolio categories are called taxonomies, but don't know if thats right.. tried this code in my functions.php but crashed my whole site!

add_action('wp_footer', 'ava_auto_click');
function ava_auto_click(){
$the_terms = get_the_terms( $post->ID , 'portfolio_entries');
for ($i=0;$i< count($the_terms); ++$i) {
    var_dump($the_terms[$i]);
if($the_terms[$i] =="projects"){     
?>
<script>
    window.onload = function(){     
        var elem = document.querySelector('.wrap-filter').querySelectorAll('li')
        var event = new Event('click');
        document.getElementById('projects').classList.remove('none')
        elem[0].setAttribute("data-filter", ".offices, .retail, .residential, .stands, .cultural");
        elem[0].firstElementChild.setAttribute("data-filter", ".offices, .retail, .residential, .stands, .cultural");
        elem[1].classList.toggle('active')
        elem[1].querySelector('a').click();

    }
</script>
<?php

    }
    else { 


        ?>
        <script>
            window.onload = function(){     
                var elem = document.querySelector('.wrap-filter').querySelectorAll('li')
                var event = new Event('click');
                document.getElementById('projects').classList.remove('none')
                elem[1].classList.toggle('active')
                elem[1].querySelector('a').click();

            }
        </script>
        <?php
         }
    }
}

Thanks in advance for the help!!

I think the main structure is right but the if and the $the_terms = get_the_terms( $post->ID , 'portfolio_entries'); might be wrong

发布评论

评论列表(0)

  1. 暂无评论