我正在使用WordPress,在搜索页面上,我需要获取该类别中的帖子数量并将其显示在名称旁边.像这样
Cat 1(3)Cat 2(1)Cat 3(18)....
目前我正在使用这些get_categories()函数,它们为您提供了一个对象并使用了$cat->count().这会抓住术语中的帖子总数,但我只需要从当前查询中的帖子中获取该计数.我pre_get_posts用来更新查询.有人知道这样做的方法吗?
这是我目前的代码块
foreach ( get_categories() as $cat ) {
if ( $cat->parent === 0 ) {
$checked = ( in_array( $cat->slug, $check ) ) ? 'checked' : '';
printf( '<input id="%1$s" %4$s type="checkbox" name="category[%1$s]"><label for="%1$s" >%2$s ( %3$d )</label><br>',
$cat->slug,
$cat->name,
$cat->count,
$checked
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的pre_get_posts行动:
add_action( 'pre_get_posts', 'breed_search_query' );
function breed_search_query( $query ) {
$cats = ( isset( $_GET['category'] ) ) ? implode( ',', array_keys( …Run Code Online (Sandbox Code Playgroud) 我创建了一个作业,它有一个 foreach 循环来调度另一个作业。有没有办法在所有嵌套作业完成后触发?
当这里触发时发生了什么
步骤 1. 首先我触发批处理作业
GenerateBatchReports::dispatch($orderable);
第 2 步。然后我们运行一个循环并将其他作业排入队列
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$dir = storage_path('reports/tmp/'.str_slug($this->event->company) . '-event');
if(file_exists($dir)) {
File::deleteDirectory($dir);
}
foreach($this->event->participants as $participant) {
$model = $participant->exercise;
GenerateSingleReport::dispatch($model);
}
}
Run Code Online (Sandbox Code Playgroud)
我只需要知道所有嵌套作业何时完成,以便我可以压缩报告并将它们通过电子邮件发送给用户。当批处理作业完成对所有嵌套作业的排队后,它将从列表中删除。有没有办法在嵌套作业完成之前保持作业,然后触发事件?
任何帮助,将不胜感激。
这可能很容易,但我无法弄明白.我已经搜索了几个小时但没有运气我的情况.我需要分页才能使用my_query
<?php
$count = 0;
$id_suffix = 1;
$items_per_row = 4;
$quality = 90;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query( array( 'posts_per_page' => '4', 'post_type' => 'portfolio') );
$grid_class = 'grid_3';
$desired_width = 220;
$desired_height = 190;
$terms = get_terms( 'portfolio_categories' );
$count_terms = count( $terms );
?>
//some php code
<?php while ( $wp_query -> have_posts()) : $wp_query -> the_post(); //query the "portfolio" custom post type for portfolio items ?>
//some more php code …Run Code Online (Sandbox Code Playgroud) 我正在使用WordPress主题,发现了一个我有点困惑的问题.我正在显示不同城市的办事处清单.这是一个自定义分类法,我使用以下代码显示一个无序的术语列表.
$wpz_offices = get_the_term_list( $post->ID, 'office', '<li>', '</li><li>', '</li>');
echo $wpz_offices;
Run Code Online (Sandbox Code Playgroud)
它显示它应该如何应该但问题是我想添加一个javascript切换如果<li>超过5.我不太了解JavaScript实现这一点,所以这就是我寻求帮助的原因.这是否可以使用可用的标记?
所以基本上如果<ul>分类法有4个或更少的术语,那么通常显示
但如果我们有5个术语表明这一点
查看所有办事处点击此处
任何帮助,将不胜感激.
更新 对于那些好奇的人我是如何使用答案的帮助 http://jsfiddle.net/KQBKu/
我试图从未经检查的数组中删除此项代码.
function filterSearch() {
var cats = [];
$('.filter-by-type input[type="checkbox"]').change(function() {
var cat = $(this).attr('name') + ', ';
if(this.checked) {
cats += cat;
} else {
cats.splice(cats.indexOf(cat), 1);
}
console.log(cats);
});
}
filterSearch();
Run Code Online (Sandbox Code Playgroud)
我收到了错误 Uncaught TypeError: cats.splice is not a function
基本上我想在cats[]检查项目时将值添加到数组中,如果未选中则删除.任何帮助,将不胜感激.
我似乎不能允许流浪者的权限。我正在尝试运行 importbuddy.php 以迁移 WordPress 实例。我收到以下错误。
file_put_contents(/path/): failed to open stream: Permission denied
我在www目录上设置了 777 的权限,但这没有任何改变。关于如何解决这个问题的任何想法?
我有一个使用 Bulma 框架的简单表单。我的输入宽度不一致并且找不到补救措施。https://jsfiddle.net/onzpum90/当标签很长时似乎会发生这种情况。如果我保留短标签,问题就消失了。为什么标签会影响输入宽度?可能是我不熟悉的flexbox问题。有人知道解决方案吗?
<form action="">
<div class="field">
<div class="field-body">
<div class="field">
<p class="control is-expanded">
<label class="label">A very long label for a form</label>
<input type="text" name="" value="" class="input ">
</p>
</div>
<div class="field is-grouped">
<p class="control is-expanded">
<label class="label">Email</label>
<input type="email" name="email" value="" class="input ">
</p>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-body">
<div class="field">
<p class="control is-expanded">
<label class="label">Short Label</label>
<input type="text" name="" value="" class="input ">
</p>
</div>
<div class="field is-grouped">
<p class="control is-expanded">
<label class="label">Email</label>
<input …Run Code Online (Sandbox Code Playgroud)