我使用WordPress作为我的CMS.我想检查我的一些用户是否在本周过生日.没有成功.
这是我的代码
$fd = date("Y-m-d",strtotime('monday this week'));
$ld = date("Y-m-d",strtotime("sunday this week"));
$cdate = date('m-d',time());
if (($cdate >= $fd) && ($cdate <= $ld)) {
echo 'true';
} else {
echo 'false';
}
Run Code Online (Sandbox Code Playgroud)
如果我使用,这对我来说是假的
'm-d' in $cdate variable
Run Code Online (Sandbox Code Playgroud)
如果使用Ymd它可以正常工作但在这种情况下,年份应该是相同的,因为所有人都有不同的出生年份
我正在使用 WordPress ajax 动态加载子类别。
这是我的代码
php代码
function techento_getsubcat() {
$category_name = $_POST['catname'];
$cat_id = $_POST['catid'];
return wp_dropdown_categories( 'show_option_none=Choose a Sub Category&tab_index=10&taxonomy=category&hide_empty=0&child_of=' . $cat_id . '' );
}
add_action('wp_ajax_techento_getsubcat', 'techento_getsubcat');
add_action('wp_ajax_nopriv_techento_getsubcat', 'techento_getsubcat');
Run Code Online (Sandbox Code Playgroud)
查询
jQuery(document).ready(function(){
$('#cat').change(function(e){
alert("changed");
$.ajax({
type: 'POST',
dataType: 'json',
url: pcAjax.ajaxurl ,
data: {
'action': 'techento_getsubcat', //calls wp_ajax_nopriv_ajaxlogin
'catname': $('#cat option:selected').text(),
'catid': $('#cat option:selected').val() },
success : function(response){
alert(response);
console.log(response);
$("#subcats").html(response);
}
});
e.preventDefault();
});
});
Run Code Online (Sandbox Code Playgroud)
上面代码的问题是 php 返回原始 html 而不考虑要求返回的内容
即使将其设置为
return true;
Run Code Online (Sandbox Code Playgroud)
然后返回生成的子类别的原始 html 加上“0”
我正在构建用户生成的内容共享主题,我想进行自定义Facebook连接.经过研究,我发现了这段代码.
以下代码将应用程序添加到Facebook中的用户配置文件,但不创建新用户,也不会使他们登录.
这是完整的代码(要添加functions.php).
function fb_head(){
if( is_user_logged_in() )
return;
?>
<script type="text/javascript">
window.fbAsyncInit = function(){
FB.init({
appId:'APP_ID',
status:true,
cookie:true,
xfbml:true,
oauth:true
});
};
</script>
<div id="fb-root"></div>
<script type="text/javascript">
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<?php
}
add_action( 'wp_head', 'fb_head' );
Run Code Online (Sandbox Code Playgroud)
<button id="facebook_connect">Connect with facebook</button>
Run Code Online (Sandbox Code Playgroud)
function mytheme_enqueue_scripts(){
wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_scripts');
Run Code Online (Sandbox Code Playgroud)
我试图从wp_nav_menu中排除页面
这是从菜单中排除页面的功能
<?php $page = get_page_by_title('my title' );
wp_nav_menu( array( 'theme_location' => 'menu-2', 'exclude' => $page->ID ) ); ?>
Run Code Online (Sandbox Code Playgroud)
工作正常
使用时请勿使用
<?php $page = get_page_by_title('my title' );
$pag1 = get_page_by_title('my title 1' );
$pag2 = get_page_by_title('my title2' );
wp_nav_menu( array( 'theme_location' => 'menu-2', 'exclude' => $page->ID,$pag1->ID,$pag2->ID ) ); ?>
Run Code Online (Sandbox Code Playgroud)
不能正常工作.