dpnvrt3119 2013-11-24 23:06
浏览 38
已采纳

Wordpress是页面str替换

I have page on wordpress site

http://upsourcemobileservices.com/solutions/

in footer.php I have added the following:

if(is_page('solutions')){
    echo str_replace("The MVNi","The MVNi solution was created to ensure that wireless communications are available to the smaller Telco operators.","The MVNi");
}

but it is not changing the contents of the page.

To my knowledge, Syntax is correct str_replace(find,replace,string)

What am I doing wrong?

I also tried using jQuery

function replaceText(jQuery) {
    $(".portfolio-thumbnail-content:nth-child(1)").replaceWith("<div class='portfolio-thumbnail-content'>The MVNi solution was created to ensure that wireless communications are available to the smaller Telco operators.</div>");
    $(".portfolio-thumbnail-content:nth-child(2)").replaceWith("<div class='portfolio-thumbnail-content'>Primarily aimed at existing Telcos our MVNc solution integrates your existing platforms with ours through the use of APIs.</div>");
    $(".portfolio-thumbnail-content:nth-child(3)").replaceWith("<div class='portfolio-thumbnail-content'>UMS turnkey solution is a complete MVNO in a box.</div>");
    $(".portfolio-thumbnail-content:nth-child(4)").replaceWith("<div class='portfolio-thumbnail-content'>This solution allows you to select the products and services that you want and integrate them with your existing platforms.</div>");
}
$(document).ready(replaceText);

but can't seem to get that working either, here's a fiddle http://jsfiddle.net/vzy9R/3/

  • 写回答

1条回答 默认 最新

  • dongyouzhi7218 2013-12-15 18:51
    关注

    I used jQuery eq() selector to find elements containing class portfolio-thumbnail-content and then using .replaceWith() I was able to load my teaser content (excerpts) ending with complete sentences.

    For example, the About page:

    (function ($) {
     $(".portfolio-thumbnail-content:eq(0)").replaceWith("<div class='portfolio-thumbail-content'>This is my new complete sentence teaser for Team.</div>");
     $(".portfolio-thumbnail-content:eq(1)").replaceWith("<div class='portfolio-thumbail-content'>This is my new complete sentence teaser for Partners.</div>");
    })(jQuery);
    

    Then I had to figure out a way to implement those scripts into the body of those pages, so I wrote my own shortcodes and added them to functions.php

    //[replaceTextAbout]
     function replaceTextAbout_func( $atts ){
      return "<script src='/javascript/custom/replaceText-About.js'></script>";
     }
     add_shortcode( 'replaceTextAbout', 'replaceTextAbout_func' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测