作为PHP的新手,并且在这个"函数包装器"上花了很多时间,我想我会得到一些意见和一些反馈.如果可能的话,我想得到五条评论.
在你问之前,我有很多理由想要包装其他(WordPress)函数,主要是无忧无虑的升级.能够为每个函数定义设置自定义名称对我来说也很重要,因此$wrap array.
但我离题了,这看起来是否可以接受且相对防弹?
function core_oo( $function )
{
$args = array_slice( func_get_args(), 1 );
$wrap = array
(
'comment' => 'the_comment',
'comments' => 'have_comments',
'post' => 'the_post',
'posts' => 'have_posts'
);
return call_user_func_array( $wrap[ $function ], $args );
}
Run Code Online (Sandbox Code Playgroud)
......并且函数将被称为......
core_oo( 'post', 'arg1', 'arg2' );
Run Code Online (Sandbox Code Playgroud)
非常感谢!
编辑:
在下面的每个混乱的sugeestion,这是声明$ wrap为静态的正确方法吗?
static $wrap = array
( ...
Run Code Online (Sandbox Code Playgroud) 我是wordpress的新手,所以如果我的语言出错,请继续帮助我.
使用woocommerce显示具有可变产品的商店,我希望商店链接登录页面显示具有该类别的特色图像的商店类别.
我当前的商店页面显示所有产品,其他产品页面分页,我找不到所有产品的模板.
当我进入wp-admin的商店页面并点击编辑页面时它是空的,所以我不确定他们是如何在第一个地方到达那里我看了HTML而不仅仅是可视化编辑器.
非常感谢Asa.
我不确定是否有人可以帮助我,但我在修改wordpress的主题时遇到了这段代码.class ="none"在这有什么影响?在任何地方都没有css指向这个类.
<a class="post-thumb none" id="thumb-165" href="" title="">
<span class="no-img" style="width:90px;height:90px"></span>
</a>
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我已经将wordpress更新为3.5并且出现此错误,js无效.
未捕获的TypeError:无法调用未定义的方法'ajax'
为什么我收到此错误?
function goToIndexforsave() {
document.getElementById('sorted_successmsg_div').innerHTML = 'processing ...';
var img_save_url = 'http://www.holidayvillas4hire.com/index.php?page=sort_image&pid='+document.getElementById('image_sort').value;
$.ajax({
url: img_save_url ,
type: 'GET',
dataType: 'html',
timeout: 20000,
error: function() {
alert('Error loading agent favorite property.');
},
success: function(html) {
document.getElementById('sorted_successmsg_div').innerHTML = html;
}
});
return false;
}
Run Code Online (Sandbox Code Playgroud) 我在wordpress http://heather.stevenspiel.com/上有一个简单的博客,我正在努力使标题标题成为主页的链接.我进入了header.php并重写了该部分的脚本,但仍无法获得工作链接.
这就是我重写的内容:
<h1>
<a href="http://heather.stevenspiel.com/" style="cursor:pointer !important;">My Spiel</a>
<br/>
</h1>
Run Code Online (Sandbox Code Playgroud)
我知道由于css颜色的变化,href正在注册.
这是以前的代码:
<h1>
<?php
if ($balloons_option['balloons_site-title_line1'] == '' && $balloons_option['balloons_site-title_line2'] == '') { ?>
This is a<br />
WordPress theme
<?php } else {
echo $balloons_option['balloons_site-title_line1']; ?><br />
<?php echo $balloons_option['balloons_site-title_line2'];
} ?>
</h1>
Run Code Online (Sandbox Code Playgroud)
我最初尝试将href放在h1之外,但仍然没有运气.
是否有一些隐藏的Wordpress设置会禁用可点击的标题?或者是否有一些我应该注意的JavaScript是禁用它?
我还应该注意标题的css包含一个z-index.我读到某处可能会受到影响:
#header .content {
line-height: 18px;
margin: 0;
z-index: 4;
}
Run Code Online (Sandbox Code Playgroud)
如果z-index正在影响它,那为什么呢?
有人可以告诉我如何呈现自定义帖子类型元字段(元框).我有一个名为"新闻"的自定义帖子类型,我成功地将一个元数据添加到我的自定义帖子类型,称为"新闻信息",它假设存储:
一个TextField =新闻资源
一个选择选项=新闻类型
一个复选框

我可以使用自定义循环检索自定义帖子类型"新闻"内容:
<?php
$args = array( 'post_type' => 'news');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="content">';
the_content();
echo '</div>';
endwhile;
?>
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将相关的元字段添加到"新闻"帖子中?相信我,谷歌这很多,但找不到任何解决方案所有这些只是试图在管理页面上呈现Metabox但没有样本在页面上呈现!你能告诉我如何使用wp-query循环访问和呈现页面上的数据吗?
谢谢
我有多个复选框,我想保存复选框并在update_post_meta中更新它,以便下次当用户编辑帖子时,他会知道已经检查了哪些复选框.我不知道我哪里出错了.这是我的代码:
add_action( 'add_meta_boxes', 'add_custom_box' );
function add_custom_box( $post ) {
add_meta_box(
'Meta Box', // ID, should be a string
'Music', // Meta Box Title
'music_meta_box', // Your call back function, this is where your form field will go
'post', // The post type you want this to show up on, can be post, page, or custom post type
'side', // The placement of your meta box, can be normal or side
'core' // The priority in which this will be …Run Code Online (Sandbox Code Playgroud) 覆盖某个类的woocomerce plugins目录中定义的woocomerce函数的最佳方法是什么。例如,我想更改类中声明的函数。我可以通过更改保留更改插件目录中的功能代码,直到升级woocomerce插件为止。如何在主题文件中覆盖它?start_elWC_Product_Cat_List_Walkerfunctions.php
php wordpress wordpress-theming wordpress-plugin woocommerce
我试图将styles.css样式表包含在我正在尝试开发的wordpress主题中(我的第一个).问题:如何包含它?我知道将以下代码放在我的header.php文件中:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
Run Code Online (Sandbox Code Playgroud)
但我宁愿通过functions.php包含它,如下所示:
<?php
function firstTheme_style(){
wp_enqueue_style( 'core', 'style.css', false );
}
add_action('wp_enqueue_scripts', 'firstTheme_style');
?>
Run Code Online (Sandbox Code Playgroud)
但是这根本不起作用(当我从header.phps'head'中删除该行时,我的样式没有被看到?
<?php
if (isset($_POST['sbt'])) {
//user posted variables
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//php mailer variables
$to = get_option('aaaa@gmail.com');
$subject = "Report";
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
echo "check";
//Here put your Validation and send mail
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
if($sent) {
echo "sent";
}//mail sent!
else {
echo "failed";
}//message wasn't sent
}
?>Run Code Online (Sandbox Code Playgroud)
我已经开发了自己的文字出版网站,我需要在联系表单中使用WP_mail()函数。
请帮我。
wordpress wordpress-theming custom-wordpress-pages wordpress-thesis-theme