我有一个带有四个标签的饼图:
var data = [{
data: [50, 55, 60, 33],
labels: ["India", "China", "US", "Canada"],
backgroundColor: [
"#4b77a9",
"#5f255f",
"#d21243",
"#B27200"
],
borderColor: "#fff"
}];
Run Code Online (Sandbox Code Playgroud)
使用chartjs-plugin-datalabels
插件我想用下面的代码显示每个Pie片中的百分比值:
formatter: (value, ctx) => {
let datasets = ctx.chart.data.datasets;
if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
let sum = 0;
datasets.map(dataset => {
sum += dataset.data[ctx.dataIndex];
});
let percentage = Math.round((value / sum) * 100) + '%';
return percentage;
} else {
return percentage;
}
},
color: '#fff',
}
Run Code Online (Sandbox Code Playgroud)
我获得了所有馅饼的100%价值,而不是相应的百分比.这是JSFiddle(https://jsfiddle.net/kingBethal/a1Lvn4eb/7/)
我想在我的WordPress中获取所有帖子标签.下面是我在页脚中的代码:
<?php
global $wpdb;
$tags = get_terms('post_tag');
echo '<ul>';
foreach ($tags as $tag)
{
echo '<li>' . $tag->name . '</li>';
}
echo '</ul>';
?>
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我只获得与特定帖子相关联的标签,而不是WordPress中的整个标签列表.
任何帮助将不胜感激.谢谢.
在我的 WordPress v5.8.1 中,我有一个在自定义帖子song
和poem
. 使用下面的代码,我可以获得在两个或一个自定义帖子中发布的作者列表。
$authors = get_users(array(
'who' => 'authors',
'has_published_posts' => array('song','poem'),
'orderby' => 'post_count',
'order' => 'DESC',
'number' => '15'
));
Run Code Online (Sandbox Code Playgroud)
下面的代码列出了所有作者及其帖子数:
foreach ($authors as $user) {
$name = $user->first_name . ' ' . $user->last_name;
$songs = count_user_posts($user->ID, $post_type = "song");
$poems = count_user_posts($user->ID, $post_type = "poem");
echo $name.' has '. $songs .' songs, and '. $poems .' poems;
}
Run Code Online (Sandbox Code Playgroud)
在参数中'orderby' => 'post_count'
,我希望首先显示组合自定义帖子数最高的作者列表,但它是随机显示的,没有顺序,既不是 bypost_counts
也不是ID
。
如何对帖子总数最多的作者进行排序?
我不是一个普通的开发人员。
我想要的只是为select2添加语言翻译;翻译默认src/js/select2/i18n/en.js
文件内容,创建新文件,将标签从英文更改为非英文。
提交拉取请求后,我看到所有检查都失败了,并且低于 CI/Linting 结果:
Run grunt compile lint
Running "requirejs:dist" (requirejs) task
Error: ENOENT: no such file or directory, open
'/home/runner/work/select2/select2/src/js/select2/i18n/en.js'
In module tree:
select2/core
select2/options
select2/defaults
Warning: RequireJS failed. Use --force to continue.
Aborted due to warnings.
##[error]Process completed with exit code 6.
Run Code Online (Sandbox Code Playgroud)
CI/Tests 和 CI/Minification 的结果相同。需要做什么才能成功合并翻译文件。
在 WordPress v5.5.1 中,我使用了以下功能来限制作者发布帖子:
function set_capabilities() {
$author = get_role('author');
$caps = array(
'edit_others_posts',
'edit_others_pages',
'publish_posts',
'delete_posts',
'delete_published_posts',
);
foreach ($caps as $cap) {
$author->remove_cap($cap);
}
}
add_action('init', 'set_capabilities');
Run Code Online (Sandbox Code Playgroud)
这导致完全删除帖子页面并在wp-admin/post-new.php
.
我已删除该set_capabilities()
功能,但仍然收到错误消息“抱歉,您无权访问此页面。”。
我试过重置wp-capabilities
,它仍然对我不起作用。
我尝试添加一个具有author
角色的新用户,新用户也有同样的问题。
我怎样才能让作者创建一个wp-admin/post-new.php
再次访问的帖子?
在我的 WP v6.1 中,我有两种自定义端口类型:company
和product
自定义分类法country
。
所需的 URL 结构分别为%country%/%company_postname%
和%country%/%product_postname%
下面是代码$wp_rewrite
:
add_action('init', 'custom_init');
function custom_init() {
global $wp_rewrite;
$company_url = '/%country%/%company_postname%';
$product_url = '/%country%/%product_postname%';
$wp_rewrite->add_permastruct('company', $company_url, false);
$wp_rewrite->add_permastruct('product', $product_url, false);
$wp_rewrite->add_rewrite_tag("%company_postname%", '([^/]+)', "company=");
$wp_rewrite->add_rewrite_tag("%product_postname%", '([^/]+)', "product=");
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码和另一个post_type_link
过滤器函数,我可以生成自定义 URL。但是这个问题是正常的post
,并且page
没有发现帖子返回error_404
。
常规帖子/页面标准 URL 结构:www.example.com/%postname%
试过add_permastruct
过帖子和页面,但没有成功。在拥有自定义帖子的自定义 URL 的同时,如何显示页面和帖子。
更新1 自定义帖子和分类法是通过代码创建的。
company
代码示例
function company_post_type() {
$labels = array(
'name' => _x('Company', 'Post Type General …
Run Code Online (Sandbox Code Playgroud) 我有下面的混合图表,带有条形和线条:
在生成上述图表的代码下方:
var data = [{
label: 'Varience 1',
data: [15, -6, -6, 7],
borderColor: '#03A9F4',
pointBackgroundColor: '#03A9F4',
pointBorderWidth: 2,
pointStyle: 'rect',
type: 'line',
steppedLine: true,
borderWidth: 2
}, {
label: 'Varience 2',
data: [24, -2, 3, 19],
borderColor: '#FF5722',
pointBackgroundColor: '#FF5722',
pointBorderWidth: 2,
pointStyle: 'rect',
type: 'line',
steppedLine: true,
borderWidth: 2
}, {
label: 'Available',
data: [72, 62, 55, 65],
borderDash: [5, 5],
borderColor: '#bbb',
pointBackgroundColor: '#bbb',
pointBorderWidth: 2,
borderWidth: 2,
type: 'line'
}, {
label: 'Budget',
data: [50, …
Run Code Online (Sandbox Code Playgroud) 我有这样的HTML列表项:
<ul id="fruits">
<li><a href="#">Mango</a></li>
<li><a href="#">Apple</a></li>
<li><a href="#">Grape</a></li>
<li><a href="#">Cherry</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
用户不会看到这些项目,因为我们将所有样式都隐藏起来display: none;
。用户可以从以下input
字段搜索这些项目:
<input type="text" id="searchInput" onkeyup="fruitSearch()" placeholder="Search fruits">
Run Code Online (Sandbox Code Playgroud)
当用户开始在input
字段上搜索水果名称时,它将列出匹配的名称,就像google搜索建议一样。使用下面的JavaScript进行搜索:
function fruitSearch() {
// Declare variables
var input, filter, ul, li, a, i;
input = document.getElementById('searchInput');
filter = input.value.toUpperCase();
ul = document.getElementById("fruits");
li = ul.getElementsByTagName('li');
// Loop through all list items, and show those who match the search query
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
if (a.innerHTML.toUpperCase().indexOf(filter) …
Run Code Online (Sandbox Code Playgroud) 在我的 WordPress 中v5.6
,我在作者页面中使用以下代码来显示自定义歌曲中的所有当前作者post_type
的帖子。
<?php
$author_page_link = esc_url(get_author_posts_url(false, ID->user_nicename));
?>
<a href="' . $author_page_link . '?post_type=song">All Songs</a>
Run Code Online (Sandbox Code Playgroud)
上面的链接将过滤当前作者的所有歌曲,其 URL 如下:
http://www.music.com/author/current_author/?post_type=song
我想在过滤器页面中显示作者的“歌曲”和“诗歌”自定义帖子。
我尝试过下面的链接,但没有成功:
<a href="' . $author_page_link . '?post_type=song+poem">All</a>
<a href="' . $author_page_link . '?post_type=song&post_type=poem">All</a>
Run Code Online (Sandbox Code Playgroud)
如何获得一个链接来过滤单个作者的多个自定义帖子中的帖子?
更新1
我使用的是archive-song.php
模板,这就是为什么song
页面中只显示自定义帖子。
当将以下 URL 与 一起使用时?post_type=song+poem
,archive.php
仅在模板层次结构中,URL 重定向到author.php
。
http://www.music.com/author/current_author/?post_type=song+poem
如果我将以下 URL 与 一起使用?post_type=song&post_type=poem
,仅在模板层次结构中,则仅过滤archive.php
最后的结果(可以是诗歌或歌曲,以最后一个查询为准)。post_type
http://www.music.com/author/current_author/?post_type=song&post_type=poem
更新2
这是我的作者页面(https://pastebin.com/kCrYebcD)。此页面仅显示所有帖子类型的当前作者的最新 10 篇帖子。
这是我的存档页面(https://pastebin.com/twkWn5Bc)。在这里,我想显示作者所有帖子类型的所有帖子。