0

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 -->
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
cyberoy
  • 363
  • 2
  • 7
  • 18
  • The question is unclear, but this might help: [How do I run PHP code when a user clicks on a link?](http://stackoverflow.com/questions/1280767/how-do-i-run-php-code-when-a-user-clicks-on-a-link) – Yogi Feb 22 '16 at 15:44

1 Answers1

1

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.

s_mart
  • 735
  • 7
  • 21