【发布时间】:2018-11-05 19:43:11
【问题描述】:
我想从我的 functions.php 文件中将 posts_per_page 输入的 'min' 属性更改为 '2'。
options-reading.php
<input name="posts_per_page" type="number" step="1" min="1" id="posts_per_page" value="<?php form_option( 'posts_per_page' ); ?>" class="small-text" /> <?php _e( 'posts' ); ?>
这是我拥有的,但它不起作用。
functions.php
function my_enqueue($hook) {
if ( 'options-reading.php' != $hook ) {
return;
}
wp_enqueue_script( 'custom-javascript', get_template_directory_uri()
.'/assets/js/custom.js', '20151215', true );
}
add_action( 'admin_enqueue_scripts', 'my_enqueue');
custom.js
jQuery("#posts_per_page").attr({
"min" : 2
});
P.S:我在 options-reading.php 的末尾添加了 javascript 代码并且效果很好,所以看起来问题与 javascript 无关。
【问题讨论】:
-
试试
jQuery("#posts_per_page").attr("min", 2); -
同理,不行。
-
文件是
custom.php还是custom.js? -
抱歉,这是 custom.js,已经修复。
标签: javascript php jquery wordpress wordpress-theming