wordpress - 从 Jetpack 的“热门帖子和页面”小部件中排除页面
问题描述
我有以下情况。(带有 Jetpack 的 WordPress)
某些“自定义”页面仅在提供数据(例如搜索词)时才显示某些内容。如果没有,页面通常是“空白的”。当它们被访问时(通过包括查询变量的链接),它们被计入统计数据中。但是...如果您在“热门帖子和页面”(小部件)下单击它们,它们只是空白。
有没有办法不在“热门帖子和页面”下列出这些特定页面?或者我可以将统计信息从子页面重定向到父页面吗?
提前致谢
解决方案
您可以挂钩jetpack_widget_get_top_posts
以从热门帖子和页面小部件中排除这些页面。
将以下代码添加到主题的 functions.php 文件中:
function wp653886_exclude_from_top_posts( $posts, $post_ids, $count ) {
$page_ids_to_exclude = array( 144, 764, 876 ); // Put here the IDs of the pages you wish to exclude.
foreach ( $posts as $k => $post ) {
// Remove this item from the list
if ( in_array( $post['post_id'], $page_ids_to_exclude ) ) {
unset( $posts[$k] );
}
}
return $posts;
}
add_filter( 'jetpack_widget_get_top_posts', 'wp653886_exclude_from_top_posts', 10, 3 );
编辑$page_ids_to_exclude
数组以添加要从小部件中排除的页面的 ID,一切顺利。
推荐阅读
- xpath - 从页面获取最相关的内容
- neo4j - Neo4j 桌面 - 应用程序显示为“未安装”
- java - 如何实现多个线程安全的读/写锁(ConcurrentHashmap)
- c++ - 在 ifs() C++ 中快速访问文件位置
- jquery - 使用 jquery .each 循环遍历 div 并检索 data-src
- angular - 为什么复选框事件状态返回字符串“on”而不是 true/false?
- maven - 如果以下配置在maven中重复
- python-3.x - 菜单栏被框架禁用
- ruby - || 和 && 不是 Object 上的方法——它们是什么?
- numpy - 我在哪里可以找到关于 NumPy 对其目录的描述的文档?