小编Max*_*ime的帖子

Wordpress 3.5自定义媒体上传为您的主题选项

最近发布了Wordpress 3.5,我通过thickbox使用了Wordpress Media Upload系统,并window.send_to_editor在我的Wordpress主题(背景,徽标等)中使用了一些选项.

但是如你所知,Wordpress集成了一个新的媒体管理器,我想用这个新功能上传图像/文件作为自定义字段.所以我花了一个上午的时间来找到一种方法来获得希望的结果.

我找到了这个解决方案,这对你们中的一些人很有用.感谢您提供有关代码或您所考虑的任何改进的反馈!

HTML示例:

<a href="#" class="custom_media_upload">Upload</a>
<img class="custom_media_image" src="" />
<input class="custom_media_url" type="text" name="attachment_url" value="">
<input class="custom_media_id" type="text" name="attachment_id" value="">
Run Code Online (Sandbox Code Playgroud)

jQuery代码:

$('.custom_media_upload').click(function() {

    var send_attachment_bkp = wp.media.editor.send.attachment;

    wp.media.editor.send.attachment = function(props, attachment) {

        $('.custom_media_image').attr('src', attachment.url);
        $('.custom_media_url').val(attachment.url);
        $('.custom_media_id').val(attachment.id);

        wp.media.editor.send.attachment = send_attachment_bkp;
    }

    wp.media.editor.open();

    return false;
});
Run Code Online (Sandbox Code Playgroud)

如果您想查看attachment变量中包含的每个设置,您可以执行console.log(attachment)alert(attachment).

wordpress jquery file-upload wordpress-3.5

66
推荐指数
3
解决办法
3万
查看次数

如何使用Wordpress在URL中传递额外的变量

我在尝试将url中的额外变量传递给我的wordpress安装时遇到了麻烦.

例如 /news?c=123

出于某种原因,它仅适用于网站根目录,www.example.com?c=123但如果网址包含更多信息则不起作用www.example.com/news?c=123.我在theme目录中的functions.php文件中有以下代码.

if (isset($_GET['c'])) 
{
  setcookie("cCookie", $_GET['c']); 
}

if (isset($_SERVER['HTTP_REFERER']))
{
  setcookie("rCookie", $_SERVER['HTTP_REFERER']);
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

php url wordpress get

65
推荐指数
4
解决办法
20万
查看次数

wp_nav_menu更改子菜单类名?

有没有办法将<ul class="sub-menu">Wordpress本身生成的子项更改为自定义类名?

我知道你可以删除或更改名称的父级ul <ul>

我找不到......试过了'menu_class' => 'newname' :D对我来说似乎是合乎逻辑的,但显然这不是正确的......

有任何想法吗?

wordpress

62
推荐指数
7
解决办法
11万
查看次数

61
推荐指数
7
解决办法
10万
查看次数

如何在自定义.php文件中包含Wordpress函数?

如何在自定义.php文件中包含Wordpress函数?

详细说明:我的主题(构造函数)下有一个名为reports的目录.它们包含.php文件,这些文件使用DOMPDF从站点的数据生成报告以供下载.对于这些,我想使用Wordpress引擎提供的功能,例如get_the_author_meta( 'user_firstname', $user_id ).如果我使用这些我得到(自然)以下错误:

致命错误:在第15行的ROOT/public_html/wp-content/themes/constructor/reports/testreport.php中调用未定义的函数get_the_author_meta()

我一直认为我需要包含wp-blog-header.php.我用require_once("../../../../wp-blog-header.php");.有了这个,我得到以下404错误:

找不到网址的网页:ROOT/wp-content/themes/constructor/reports/testreport.php

(要求指向正确的路径.如果我操作它,我得到警告:require_once(../../../ wp-blog-header.php):无法打开流...所以路径必须是对的.)

有什么我忽略的吗?为什么我不能包含这个wp文件?包含wp函数的正确方法是什么?

谢谢你的帮助,Sziro

php wordpress include

59
推荐指数
2
解决办法
8万
查看次数

如何删除wordpress网站上的bitnami横幅

我使用bitnami安装了wordpress,现在我在wordpress网站的页面右下角有了bitnami横幅.我该如何删除它?

wordpress banner bitnami

57
推荐指数
5
解决办法
5万
查看次数

为什么wordpress在使用wp_register_script()时会放置"text/rocketscript"而不是"text/javascript"?

我在wordpress插件中插入了以下代码:

   wp_deregister_script('jquery');
   wp_register_script('jquery', "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
   wp_enqueue_script('jquery');
Run Code Online (Sandbox Code Playgroud)

以下内容与浏览器相呼应:

<script type='text/rocketscript' data-rocketsrc='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js?ver=3.3.1'></script>
Run Code Online (Sandbox Code Playgroud)

代替:

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
Run Code Online (Sandbox Code Playgroud)

我不知道发生了什么.也许wp_register_script()应该以这种方式工作.我还测试了是否有任何jquery代码在客户端工作,但它没有.请帮忙...

wordpress

51
推荐指数
2
解决办法
7万
查看次数

如何设置ChartJS Y轴标题?

我使用Chartjs来显示图表,我需要设置y轴的标题,但在文档中没有关于它的信息.

我需要像在图片上一样设置y轴,或者在y轴的顶部设置,所以有人可以现在是什么参数

我在官方网站上看过,但没有关于它的信息

javascript jquery charts chart.js

51
推荐指数
6
解决办法
9万
查看次数

Wordpress 4.5更新后插件抛出TypeError

我正在调试一个可视化作曲家插件,在我将Wordpress更新到4.5之后就破坏了,我无法弄清楚它为什么会抛出TypeError.

控制台中的错误消息:

JQMIGRATE: Migrate is installed, version 1.4.0              load-scripts.php?....
Uncaught TypeError:     $template.get is not a function     composer-view.js?ver=4.1.1.1:73
Run Code Online (Sandbox Code Playgroud)

唯一出现的$template情况可以在下面的代码中找到.我明白这不是很多背景,但是,我该如何解决这个错误呢?

/**
 * Convert html into correct element
 * @param html
 */
html2element: function(html) {
  var attributes = {},
    $template;
  if (_.isString(html)) {
    this.template = _.template(html);
    $template = $(this.template(this.model.toJSON()).trim());
  } else {
    this.template = html;
    $template = html;
  }
  _.each($template.get(0).attributes, function(attr) { // **errors on this line**
    attributes[attr.name] = attr.value;
  });
  this.$el.attr(attributes).html($template.html());
  this.setContent();
  this.renderContent();
},
Run Code Online (Sandbox Code Playgroud)


更新:

看起来这可能是jQuery的一个问题.Wordpress 4.5包含jQuery 1.12,修复了一个允许某些代码以不正确的语法运行的错误.我假设插件代码必须具有不正确的语法,但直到现在仍然运行.

https://wordpress.org/support/topic/read-this-first-wordpress-45-master-list#post-8271654

html javascript wordpress jquery

51
推荐指数
4
解决办法
5万
查看次数

从命令行执行SQL脚本

我需要使用批处理文件来更改数据库,举一个简单的例子,删除一个表.我使用本地SQL Express(SQL Server 2008 R2)与用户sa及其密码.

bat文件怎么样?

如何在脚本中指定密码和我在SQL Express中使用的密码?

sql sql-server scripting command-line batch-file

50
推荐指数
4
解决办法
11万
查看次数