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

Loading elements with a button

programmeradmin1浏览0评论

I am trying to display some elements in a template file when a user clicks a button, specifically an image gallery and another separate template part. The following doesn't break the site but doesn't work either,

<div>
        <button onclick="myFunction()" id="loadOverlays" type="button">LOAD OVERLAYS</button>
</div>

<script>
function myFunction() {
    <div>   
        <?php
        $item_id = get_the_ID();
        $tags = get_the_terms( $item_id, 'attachment_tag' );
        $slug = '';
        foreach ( $tags as $tag ) {
            if ( 0 === strpos( $tag->name, 'Portrayal:' ) ) {
                $slug = 'overlay' . substr( $tag->slug, strlen( 'portrayal' ));
                break;
            }
        }

        if ( !empty( $slug ) ) {
            echo do_shortcode( sprintf( '[mla_gallery attachment_tag="%1$s" ]', $slug ) );
        }
        ?>  
    </div>
    <?php get_template_part( 'exn', 'overlays' ); ?>
}
</script>

It needs some magic sauce to force it to actually display.

Thanks,

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论