dp709369831 2016-02-22 15: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 16: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.

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

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭