我正在研究WordPress主题,并添加了一个选择框,以允许用户选择其网站的字体。我以为我会使用Google字体API来获取字体列表,而不是手动添加所有900多种字体,但是当我调用该API时,无法将返回的数据作为选择框的选项追加。
这是我的选择框类的PHP代码:
class Customize_Select_Control extends WP_Customize_Control {
public $type = 'select';
public function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<select <?php $this->link(); ?> id="<?php echo str_replace(' ','-',strtolower(esc_html( $this->label ))); ?>-select">
<option value="<?php echo $this->value(); ?>" selected><?php echo $this->value(); ?></option>
</select>
</label>
<?php
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我使用以下代码向定制器添加了一个部分,进行设置和控制:
// Add Font Section
$wp_customize->add_section( 'fonts' , array(
'title' => __( 'Font', 'wordpress' ),
'priority' => 100,
'description' => __( 'Pick a font for your website.', 'wordpress' )
) ); …Run Code Online (Sandbox Code Playgroud) 我目前正在使用沙箱 API,我可以查询产品,包括单独查询,但如果我尝试下购买订单,我得到的响应是{ message: 'Product not found' }.
这是我的代码:
async function cb_request( method, path, headers = {}, body = ''){
var apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
apiSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
apiPass = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
//get unix time in seconds
var timestamp = Math.floor(Date.now() / 1000);
// set the request message
var message = timestamp + method + path + body;
//create a hexedecimal encoded SHA256 signature of the message
var key = Buffer.from(apiSecret, 'base64');
var signature = crypto.createHmac('sha256', key).update(message).digest('base64');
//create the request options …Run Code Online (Sandbox Code Playgroud) 我设置了一些 ACF 字段的自定义帖子类型。我还设置了 ACF 选项页面。
当选项页面更新时,我试图使用选项页面内文本字段中的值来更新所有自定义帖子上的文本字段。
这是我尝试过的:
function update_global_flash_text(){
$current_page = get_current_screen()->base;
if($current_page == 'toplevel_page_options') {
function update_global_servicing_text() {
$args = array(
'post_type' => 'custom',
'nopaging' => true,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
update_field('servicing_flash_text', $_POST['global_servicing_offer_text']);
}
}
wp_reset_postdata();
}
if(array_key_exists('post',$_POST)){
update_global_servicing_text();
}
}
}
add_action('admin_head','update_global_flash_text');
Run Code Online (Sandbox Code Playgroud)
理想情况下,我还想仅在全局字段值发生更改时更新 posts 字段。
我正在制作一个BMI计算器(参见JSFiddle - http://jsfiddle.net/b5ww2/),我希望以英寸为单位的高度以英尺和英寸显示.我还希望以磅为单位的重量以磅和磅显示.
这是我用来将滑块值转换为cm和inch的代码:
slide: function( event, ui ) {
$( "#heightslidecm" ).html( ui.value + 'cm' );
$( "#heightslidein" ).html( (ui.value*0.393700787).toFixed(0) + 'in' );
}
Run Code Online (Sandbox Code Playgroud)
我的知识并不是很好 - 尤其是在数学方面.
有任何想法吗?
提前致谢
我正在尝试将自定义设置选项卡添加到 WooCommerce 设置屏幕。基本上我想通过子部分/子选项卡实现与“产品设置”选项卡类似的功能:
我无法找到任何关于如何执行此操作的像样文档,但我已经能够使用以下代码段添加自定义选项卡:
class WC_Settings_Tab_Demo {
public static function init() {
add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 50 );
}
public static function add_settings_tab( $settings_tabs ) {
$settings_tabs['test'] = __( 'Settings Demo Tab', 'woocommerce-settings-tab-demo' );
return $settings_tabs;
}
}
WC_Settings_Tab_Demo::init();
Run Code Online (Sandbox Code Playgroud)
根据我从各种线程/教程中挖掘出的内容,我一直在尝试将部分/子选项卡添加到新的设置选项卡中,如下所示:
// creating a new sub tab in API settings
add_filter( 'woocommerce_get_sections_test','add_subtab' );
function add_subtab( $sections ) {
$sections['custom_settings'] = __( 'Custom Settings', 'woocommerce-custom-settings-tab' );
$sections['more_settings'] = __( 'More Settings', 'woocommerce-custom-settings-tab' );
return $sections;
}
// adding settings (HTML Form) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码过滤一些带有复选框的 div:
$("#filterControls :checkbox").click(function() {
$(".sectionContent").hide();
$("#filterControls :checkbox:checked").each(function() {
$("." + $(this).val()).show();
});
if($("#filterControls :checkbox").prop('checked') == false){
$(".sectionContent").show();
}
});
Run Code Online (Sandbox Code Playgroud)
当您选中第一个复选框时,这可以正常工作,但只有在您选择了第一个复选框时,它才会与其他复选框一起过滤。很难解释,但试试 JSFiddle:http : //jsfiddle.net/BY9JL/
我不希望它依赖于选中第一个复选框,有没有办法解决这个问题?
我正在处理一个简单的 React 购物清单,您可以在其中添加/删除列表中的项目(这里是pen)。到目前为止,它运行良好,除非您向列表中添加重复条目并尝试删除它,否则它会感到困惑(它使用值作为键,所以大概这就是原因)。为了解决这个问题,我想在添加项目时检查列表数组中是否已经存在该值,并防止它被添加。我尝试通过将 this: 更改if (this.state.newItem.length > 0){为 this:(if (this.state.newItem.length > 0 && this.state.items.includes(this.state.newItem) == false){第 18 行)在 handleAddNew 函数中添加另一个检查,但这似乎不起作用。关于我应该如何去做的任何想法?
我正在使用SPServices从SharePoint列表中提取数据.列表中的每一行都将插入到容器div中,其中的类与列表中的月份和年份数据相对应,如下所示:
<div class="container">
<div class="child 07-2013">
<p>Some content</p>
</div>
<div class="child 06-2013">
<p>Some content</p>
</div>
<div class="child 06-2013">
<p>Some content</p>
</div>
<div class="child 11-2012">
<p>Some content</p>
</div>
<div class="child 11-2012">
<p>Some content</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我需要编写一个脚本(最好是jQuery而不是正确的JavaScript,因为我对它更熟悉),它会找到每个类的第一个并在它之前添加另一个div,这样它最终会像这样:
<div class="container">
<div class="header">July 2013</div>
<div class="child 07-2013">
<p>Some content</p>
</div>
<div class="header">June 2013</div>
<div class="child 06-2013">
<p>Some content</p>
</div>
<div class="child 06-2013">
<p>Some content</p>
</div>
<div class="header">November 2012</div>
<div class="child 11-2012">
<p>Some content</p>
</div>
<div class="child 11-2012">
<p>Some content</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我知道我可以这样写:
function addHeaders(){ …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个具有多个部分的表单,其中包含"是/否"单选按钮和文本区域.页面加载时,textareas被禁用,默认情况下会检查所有"no"单选按钮.我试图得到它,以便一旦用户选择"是"单选按钮,禁用的属性将从相关的textarea中删除.
我正在尝试使用next('textarea'),但这似乎不起作用.奇怪的是,兄弟姐妹确实有效(使用相同的选择器),但显然它针对的是所有textareas而不仅仅是相关的.
有任何想法吗?
这是我的代码(简化):
<input type="radio" value="Yes" name="rdo" />Yes
<input type="radio" value="No" name="rdo" checked/>No
<br />
<textarea rows="4" cols="50" disabled></textarea>
$(document).ready(function(){
$(":radio[value=Yes]").click(function(){
if ($(this).attr('checked','true')) {
$(this).next('textarea').removeAttr('disabled');
}
});
});
Run Code Online (Sandbox Code Playgroud)
见JSFiddle:http://jsfiddle.net/AThomas92/Ry2fX/
干杯,
灰
javascript ×7
jquery ×5
html ×4
php ×3
wordpress ×3
arraylist ×1
arrays ×1
backend ×1
checkbox ×1
coinbase-api ×1
database ×1
filtering ×1
list ×1
math ×1
node.js ×1
post ×1
reactjs ×1
rest ×1
settings ×1
sharepoint ×1
spservices ×1
woocommerce ×1