dp709369831 2016-02-22 07:28
浏览 53
已采纳

在php中为特定的get请求执行javascript

Suppose my domain name is www.example.com and I have a category, which contains many items. Example, Travel, Books, Education. Now, if I click on Travel the get request is www.example.com/category/travel-areas. Now, I want to execute a script when particularly that Travel is clicked from category, like <script>alert("hi")</script> it will be executed when I open www.example.com/category/travel-areas This is my category.php file :-

<div class="content">

<?php tie_breadcrumbs() ?>

<?php
    $category_id = get_query_var('cat') ;
    $tie_cats_options = get_option( 'tie_cats_options' );

    if( !empty( $tie_cats_options[ $category_id ] ) )
        $cat_options = $tie_cats_options[ $category_id ];
?>

    <div class="page-head">

        <h1 class="page-title">
            <?php echo single_cat_title( '', false ) ?>
        </h1>

        <?php if( tie_get_option( 'category_rss' ) ): ?>
        <a class="rss-cat-icon ttip" title="<?php _eti( 'Feed Subscription' ); ?>" href="<?php echo get_category_feed_link($category_id) ?>"><i class="fa fa-rss"></i></a>
        <?php endif; ?>

        <div class="stripe-line"></div>

        <?php
        if( tie_get_option( 'category_desc' ) ):    
            $category_description = category_description();
            if ( ! empty( $category_description ) )
            echo '<div class="clear"></div><div class="archive-meta">' . $category_description . '</div>';
        endif;
        ?>
    </div>

    <?php get_template_part( 'framework/parts/slider-category' ); ?>

    <?php $loop_layout = ( !empty( $cat_options[ 'category_layout' ] ) ? $cat_options[ 'category_layout' ] :  tie_get_option( 'category_layout' ) );    ?>

    <?php get_template_part( 'loop' );  ?>

    <?php if ($wp_query->max_num_pages > 1) tie_pagenavi(); ?>

</div> <!-- .content -->

展开全部

  • 写回答

1条回答 默认 最新

  • douzuo0711 2016-02-22 08:22
    关注

    In your code there is no part, where exactly link is displayed. But i can suggest that you have list of links to different areas. For example :

    <a href="#" class="travel-area" data-id="1"> Area title</a>
    

    So i added some example to Jsfiddle. As you can see, some part of JS code will be executed only when be passed if expression. You can change that expression, so add some additional check.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部