0

我认为解决这个问题的最好方法是直接跳进去,边走边解释。

我正在使用 wordpess 和一个定制的模板(我们做了它)这个代码是为了处理 twitter 小部件 pro。(这不是最漂亮的代码,我稍后会清理它)

<?php

/*
  * TWITTER SIDE BAR
  *
  * Sets the twitter area to display: none and pulls in the content from the server
  * Javascript then does a string replace to remove a bit of unwanted text
  * finally javascript will write the doctored string to the client browser
*/

?><div id="twitterRight">

  <ul class="xoxo" style="list-style-type:none; font-size:11px; margin:0px 20px 0 0;">
    <li id="twitter-2" class="widget-container widget_twitter">
    <div id="twitHold" style="display:none;">
    <h3 class="widget-title"><span class='twitterwidget twitterwidget-title'><a href="http://www.twitter.com/username" target="_blank"><img src="<?php echo home_url(); ?>/images/twitterName.png" width="208" height="27" alt="EhomeS" /></a></span></h3>

  <ul>
  <?php 
    $twitter = dynamic_sidebar('primary-widget-area');
  ?></ul>
  </div>
  <div id="twitHolder">

  <script type="text/javascript">
    // Get the posted content from the server
    var str = $('#twitHold').html();
    var x = str.replace("Twitter: @username", "");
    //var shortString = x.substr( 0, 10 );
    document.write(x);
  </script>    
  </div>

  </li></ul>
</div><!-- END #twitterRight -->

问题是 wordpress 函数 dynamic_sidebar 不返回字符串或任何东西,只返回一个布尔值,所以我无法操作它。所以我所做的就是将输出的 HTML 存储在一个 js 变量 x 中并从那里进行操作。

What I am trying to achieve is to simply limit the number of characters in each list item (tweets) however I cannot find a way of doing so. I have tried this so far with no luck (im thinking because the javascript is writing it out and parsing it, im not sure).

Is there a way to perform the substr on the list items?

4

1 回答 1

1

Question is a little unclear, if you want a collection of the list items then try this.

use a jquery selector, jquery has good documentation http://jquery.com/

be sure to add the jquery library to your document.

<ul id="twitterlist">
  <?php 
    $twitter = dynamic_sidebar('primary-widget-area');
?></ul>

<script type="text/javascript">
var listitems = $('#twitterlist').children();
</script>
于 2012-08-28T09:33:16.683 回答