2017-01-29 20 views
-1

テキストを置き換えるスクリプトがありますが、htmlコードで置き換えるにはどうしたらいいですか?私は(キープしたいjQueryでテキストをhtmlタグに置き換えてください

元のテキスト(イッツWordPressのHTMLからのショートは、私が代わりにhtmlタグでそれを交換する必要があるので、それをコンパイルすることはできませんされて)

[upside_button class=”kopa-button pink-button large-button kopa-button-icon” link="Link here" target=”_blank”] View More Photos[/upside_button]


結果リンク先と接尾辞、htmlボタンの接尾辞のみ)

<a href="Link here"><button type="button">View More Photos</button></a>


これは私がすべての投稿ページで実行する必要があります(私はWordPressを使用している)ので、それはテンプレートファイルである必要はあり

var re1 = '[upside_button class=”kopa-button pink-button large-button kopa-button-icon” link=”'; 
var re2 = '″ target=”_blank”] View More Photos[/upside_button]'; 
var rs1 = '<a href="'; 
var rs2 = '"><button type="button">View More Photos</button></a>'; 
    $('.entry-content p').each(function() 
    { 
     var text = $(this).text(); 
     $(this).text(text 
      .replace(re1, rs1) 
      .replace(re2, rs2) 
     ); 
    }); 

私のスクリプトを使用するスクリプトであります

テンプレートファイル - single.php(私の壊れたスクリプトはまだここにあります)

<?php 
    $pageStart = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
     <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script> 
     <script type="text/javascript"> 

     /*$(document).ready(function(e) { 
      $("#date").datepicker(); 
     });*/ 
     </script> 
    </head> 
    <body> 
     <!--input type="text" id="date" name="date" /--> 
    </body> 
    </html>'; 

    print $pageStart; 

?> 
<?php 
/** 
* The template for displaying all single posts and attachments 
* 
* @package WordPress 
* @subpackage Twenty_Fifteen 
* @since Twenty Fifteen 1.0 
*/ 

get_header(); ?> 

    <div id="primary" class="content-area"> 
     <main id="main" class="site-main" role="main"> 

     <?php 
     // Start the loop. 
     while (have_posts()) : the_post(); 

      echo " 
       <script type=\"text/javascript\"> 
        setInterval(
        function(){ 
         var re1 = '[upside_button class=”kopa-button pink-button large-button kopa-button-icon” link=”'; 
         var re2 = '″ target=”_blank”] View More Photos[/upside_button]'; 
         var rs1 = '<a href="'; 
         var rs2 = '"><button type="button">View More Photos</button></a>'; 
          $('.entry-content p').each(function() 
           { 
            var text = $(this).text(); 
            $(this).text(text 
             .replace(re1, rs1) 
             .replace(re2, rs2) 
            ); 
          });  
        } 
        , 1); 
       </script> 
      "; 
      /* 
      * Include the post format-specific template for the content. If you want to 
      * use this in a child theme, then include a file called called content-___.php 
      * (where ___ is the post format) and that will be used instead. 
      */ 
      get_template_part('content', get_post_format()); 

      // If comments are open or we have at least one comment, load up the comment template. 
      if (comments_open() || get_comments_number()) : 
       comments_template(); 
      endif; 

      // Previous/next post navigation. 
      /*the_post_navigation(array(
       'next_text' => '<span class="meta-nav" aria-hidden="true">' . __('Next', 'twentyfifteen') . '</span> ' . 
        '<span class="screen-reader-text">' . __('Next post:', 'twentyfifteen') . '</span> ' . 
        '<span class="post-title">%title</span>', 
       'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __('Previous', 'twentyfifteen') . '</span> ' . 
        '<span class="screen-reader-text">' . __('Previous post:', 'twentyfifteen') . '</span> ' . 
        '<span class="post-title">%title</span>', 
      ));*/ 

     // End the loop. 
     endwhile; 
     ?> 

     </main><!-- .site-main --> 
    </div><!-- .content-area --> 

<!--?php get_footer(); ?> 
+0

あなたに役立つかもしれないちょうど 'upside_button'ありますか? –

答えて

0

あなたはこの link を参照することがありますが、これは

関連する問題