Aligatro
Newbie | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Доброго времени суток уважаемое сообщество. Давеча столкнулся с такой проблемой. На сайте необходимо реализовать подгрузку js к плагину только в тех статьях где есть вызов функции отвечающий за отображение таблицы, ну или хотя бы, только в статьях определенной категории. Вот строение самого плагина (кусок кода отвечающий за вывод таблицы, за подгрузку скриптов и сам вид плагина) Код: /*-----------------------------------------------------------------------------------*/ # Register and Enquee plugin's styles and scripts /*-----------------------------------------------------------------------------------*/ function taqyeem_scripts_styles(){ if( !is_admin()){ wp_register_style( 'taqyeem-style' , plugins_url('style.css' , __FILE__) ) ; wp_enqueue_style( 'taqyeem-style' ); wp_register_script( 'taqyeem-main', plugins_url('js/tie.js' , __FILE__), array( 'jquery' ) , false , false ); wp_enqueue_script( 'taqyeem-main' ); } } add_action( 'init', 'taqyeem_scripts_styles' ); /*-----------------------------------------------------------------------------------*/ # Get Reviews Box /*-----------------------------------------------------------------------------------*/ function taqyeem_get_review( $position = "review-top" ){ if( !is_singular() && taqyeem_get_option('taq_singular') ) return false; global $post ; $get_meta = get_post_custom($post->ID); $criterias = unserialize( $get_meta['taq_review_criteria'][0] ); $title = $get_meta['taq_review_title'][0] ; $summary = htmlspecialchars_decode( $get_meta['taq_review_summary'][0] ); $short_summary = $get_meta['taq_review_total'][0] ; $style = $get_meta['taq_review_style'][0]; $image_style = taqyeem_get_option('rating_image'); if( empty($image_style) ) $image_style ='stars'; $total_score = $total_counter = $score = $ouput = 0; if( taqyeem_get_option('allowtorate') != 'none' ) $users_rate = taqyeem_get_user_rate(); else $users_rate = ''; if( $style == 'percentage' ) $review_class = ' review-percentage'; elseif( $style == 'points' ) $review_class = ' review-percentage'; else $review_class = ' review-stars'; $ouput = ' <div class="review_wrap" itemscope itemtype="http://schema.org/Review"> <div style="display:none" itemprop="reviewBody">'. wp_trim_words($post->post_content, 500 ) .'</div> <div style="display:none" class="name entry-title" itemprop="name">'. get_the_title() .'</div> <div style="display:none" class="entry-title" itemprop="itemReviewed" itemscope itemtype="http://schema.org/Thing"><span itemprop="name">'. get_the_title() .'</span></div> <div style="display:none" class="updated">'. get_the_time( 'Y-m-d' ) .'</div> <div style="display:none" class="vcard author" itemprop="author" itemscope itemtype="http://schema.org/Person"><strong class="fn" itemprop="name">'. get_the_author() .'</strong></div> <meta itemprop="datePublished" content="'. get_the_time( 'Y-m-d' ) .'" /> <div id="review-box" class="review-box '. $position.$review_class.'">'; if( !empty($title) ){ $ouput .= '<h2 class="review-box-header">'.$title.'</h2>'; } if( !empty($criterias) && is_array($criterias) ){ foreach( $criterias as $criteria){ if( $criteria['name'] && is_numeric( $criteria['score'] )){ if( $criteria['score'] > 100 ) $criteria['score'] = 100; if( $criteria['score'] < 0 ) $criteria['score'] = 0; $score += $criteria['score']; $total_counter ++; if( $style == 'percentage' ): $ouput .= ' <div class="review-item"> <span><h3>'. $criteria['name'] .' - '. $criteria['score'] .'%</h3><span data-width="'. $criteria['score'] .'"></span></span> </div>'; elseif( $style == 'points' ): $point = $criteria['score']/10; $ouput .= ' <div class="review-item"> <span><h3>'. $criteria['name'] .' - '. $point.'</h3><span data-width="'. $criteria['score'] .'"></span></span> </div>'; else: $ouput .= '<div class="review-item"> <h3>'. $criteria['name'] .'</h3> <span class="post-large-rate '.$image_style.'-large"><span style="width:'. $criteria['score'] .'%"></span></span> </div>'; endif; } } } if( !empty( $score ) && !empty( $total_counter ) ) $total_score = $score / $total_counter ; $ouput .= ' <div class="review-summary" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating"> <meta itemprop="worstRating" content = "1" /> <meta itemprop="bestRating" content = "100" /> <span class="rating points" style="display:none"><span class="rating points" itemprop="ratingValue">'. round($total_score) .'</span></span>'; if( $style == 'percentage' ): $ouput .= ' <div class="review-final-score"> <h3>'. round($total_score) .'<span>%</span></h3> <h4>'. $short_summary .'</h4> </div>'; elseif( $style == 'points' ): $total_score = $total_score/10 ; $ouput .= ' <div class="review-final-score"> <h3>'. round($total_score,1).'</h3> <h4>'. $short_summary .' </h4> </div>'; else: $ouput .= ' <div class="review-final-score"> <span title="'. $short_summary .'" class="post-large-rate '.$image_style.'-large"><span style="width:'. $total_score .'%"></span></span> <h4>'. $short_summary .'</h4> </div>'; endif; if( !empty( $summary ) ){ $ouput .= ' <div class="review-short-summary" itemprop="description"> <p>'. $summary .'</p> </div>'; } $ouput .= ' </div>'.$users_rate.' <span style="display:none" itemprop="reviewRating">'. round($total_score) .' </span> </div> </div>'; return $ouput ; } /*-----------------------------------------------------------------------------------*/ # Get Reviews Box /*-----------------------------------------------------------------------------------*/ function taqyeem_insert_review($content) { global $post; if( is_feed() ) return $content; $get_meta = get_post_custom($post->ID); if( !empty( $get_meta['taq_review_position'][0] ) ) $review_position = $get_meta['taq_review_position'][0] ; $output = $output2 = ''; if( !empty( $review_position ) && $review_position == 'top' ) $output = taqyeem_get_review('review-top'); if( !empty( $review_position ) && $review_position == 'bottom' ) $output2 = taqyeem_get_review('review-bottom'); return $output.$content.$output2; } add_filter ('the_content', 'taqyeem_insert_review'); | Я пытался сделать это множеством разных способов, вот несколько из них. 1. Код: if( taqyeem_get_review()){ wp_register_script( 'taqyeem-main', plugins_url('js/tie.js' , __FILE__), array( 'jquery' ) , false , false ); wp_enqueue_script( 'taqyeem-main' ); } | непонятно почему но подгружает скрипт на всех страницах блога, даже на главной, где упоминания о get_review даже нету. 2. Код: function taqyeem_onload(){ if( is_category('obzor')){ wp_register_script( 'taqyeem-main', plugins_url('js/tie.js' , __FILE__), array( 'jquery' ) , false , false ); wp_enqueue_script( 'taqyeem-main' ); } } add_action ('wp_head' 'taqyeem_onload') | так же безуспешно. Скрипт не подгружается вообще нигде. То же самое если я размещаю условие не при помощи хука, а вручную в head. 3. Код: if( is_singular()){ wp_register_script( 'taqyeem-main', plugins_url('js/tie.js' , __FILE__), array( 'jquery' ) , false , false ); wp_enqueue_script( 'taqyeem-main' ); } | опять таки скрипт не загружается нигде, хотя порывшись в исходниках wp с comment-reply.js - это прокатывает. Что скажите? =)) Большое спасибо за помощь =) |