0

我想在我的 Wordpress 博客中使用 Colorbox 和我的所有图像。我正在使用此命令在我的 functions.php 中添加 rel='colorbox':

 //colorbox
  // adds the colorbox jQuery code
  function insert_colorbox_js() {
  ?>
      <script type="text/javascript">
      // <![CDATA[
      jQuery(document).ready(function($){
          $("a[rel='colorbox']").colorbox({
                  transition:'elastic', 
                  opacity:'0.7', 
                  maxHeight:'90%'
          });
          $("a[rel='colorboxvideo']").colorbox({
                  iframe:true, 
                  transition:'elastic', 
                  opacity:'0.7',
                  innerWidth:'60%', 
                  innerHeight:'80%'
          });
      });  
      // ]]>
      </script>
  <?php
  }
  add_action( 'wp_head', 'insert_colorbox_js' );

  // automatically add colorbox rel attributes to embedded images
  function insert_colorbox_rel($content) {
    $pattern = '/<a(.*?)href="(.*?).(bmp|gif|jpeg|jpg|png)"(.*?)>/i';
      $replacement = '<a$1href="$2.$3" rel=\'colorbox\'$4>';
    $content = preg_replace( $pattern, $replacement, $content );
    return $content;
  }
  add_filter( 'the_content', 'insert_colorbox_rel' );

此函数条目在我的本地 Mamp 设置上运行良好,但由于我将网站移动到我的服务器,它不再工作 - rel 属性被添加到 img 标签而不是链接:

<div id="attachment_1131" class="wp-caption alignleft" style="width: 160px"><a href="http://www.somesite.net/somelink/" rel="attachment wp-att-1131"><img class="size-thumbnail wp-image-1131" title="Some title" src="http://www.somesite.net/wp-content/uploads/2011/04/CIMG0935-150x150.jpg" rel='colorbox' alt="Some Text" width="150" height="150" /></a><p class="wp-caption-text">Some other Text</p></div>

我如何必须更改 functions.php 才能使其再次工作?

谢谢你的帮助!

顺便说一句 - 我在最新的 Wordpress 3.4.2

4

1 回答 1

0

自己找到了解决方案 - 默认上传链接在我的主题中以某种方式更改。我不得不将此行添加到functions.php:

update_option('image_default_link_type' , 'file'); 

所以,上一篇文章中的函数工作得很好......

于 2012-11-22T15:20:48.530 回答