或者如何使用默认插件值填充wordpress数据库,添加选项对我来说不起作用,如http://codex.wordpress.org/Function_Reference/add_option
我确信我的语法是正确的,我想要的是,当用户进入我的插件的设置菜单时,他/她没有看到空白输入字段,而是看到它填充了默认数据.
我有一个个人主题"A",我想它也可以在没有Woocommerce的情况下工作.当添加Woocommerce"WC"插件时,我会将A产品与WC集成.我有一个名为"对象"的自定义帖子类型,如何通过WC让"对象"可以买到?
我已经看到StackOverflow上的这个答案在Woocommerce中添加自定义帖子类型 最终解决方案提供了一个免费(不再是)插件来解决.
我更喜欢自己做这件事,没有插件的帮助.我很好奇,预包装解决方案不是我想要的.
wp_get_attachment_url() 处理完整的文件路径,如
http://example.com/wp-content/uploads/2014/12/aura.mp3
Run Code Online (Sandbox Code Playgroud)
我想要没有的 urlhttp://example.com/
所以,我想要上面的例子wp-content/uploads/2014/12/aura.mp3而不是http://example.com/wp-content/uploads/2014/12/aura.mp3. 怎么做?
如何在插入新帖子时选择帖子ID,例如:
$post = array(
'ID' => 3333,
'comment_status' => 'open',
'post_content' => 'hi world!',
'post_name' => 'title_1',
'post_status' => 'publish',
'post_title' => 'sdfsfd fdsfds ds',
'post_type' => 'post',
);
$post_id = wp_insert_post($post);
Run Code Online (Sandbox Code Playgroud)
想要插入id = 3333的新帖子
有什么办法可以在wordpress Codex中获取所有已激活的插件列表。
我用这个
get_option('active_plugins');
Run Code Online (Sandbox Code Playgroud)
这将返回插件文件路径。我要这个名字。因为有时文件名与实际的插件名不同。
我用 WP_query 循环检索了首页上的最新帖子,因为我发现这是最好的解决方案。但我想显示帖子被点击在首页。
单个帖子查询的最佳方法是什么?
我在 single.php 中再次使用了 wp_query(有没有更好的主意?)
$args = array('name' => $the_slug,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 1);
$the_query = new WP_Query( $args );
<?php while ( $the_query->have_posts() ) :?>
<?php $the_query->the_post(); ?>
<p><?php $content = get_the_content('Read more');
print $content; ?></p>
<?php endwhile; ?><!-- end of the loop -->
<!-- put pagination functions here -->
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)
问题是它总是检索最新的帖子,即使我点击任何帖子 ID。我该如何解决这个问题?
我试图使用get_template_directory_uri()将图像加载到jquery.backstretch.js文件和我的styles.css.到目前为止,我将我的图像直接添加到名为"img"的文件夹中的主题文件夹中,我将其用于我的HTML:
<img src="<?php echo get_template_directory_uri(); ?>/img/logoyellow.png" class="hidden-xs" alt="logo" />
Run Code Online (Sandbox Code Playgroud)
这工作得很好!
但我在jquery文件(jquery.backtretch.js)中执行了以下操作:
$(document).ready(function () {
$("#home-section").backstretch("<?php echo get_template_directory_uri(); ?>/img/background-image2.jpg");
});
Run Code Online (Sandbox Code Playgroud)
但是没有雪茄:(我也想知道如何在我的CSS中加载它.这样的东西:
#milestones-section {
background: url('<?php echo get_template_directory_uri(); ?>/img/hbg.jpg') center center;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!