建站教程

建站教程

Products

当前位置:首页 > 建站教程 >

可能是最被低估的跨平台云笔记工具 开源、免费、轻量级(如何让WordPress分类标签页支持置顶文章)

GG网络技术分享 2025-03-18 16:12 0


可能是最被低估的跨平台云笔记工具 开源、免费、轻量级

Simplenote 是一个简单、轻量级的开源跨平台云笔记工具,可以保存笔记、列表,支持 Markdown,拥有多人协作、历史版本、标签、公开分享等功能,开发者是 WordPress 母公司 Automattic。

其实 Simplenote 发布很久了,要不是朋友再次提到,2T怕是不会在试了,所以标题其实是被低估了。

Simplenote 属于那种超简单功能的云笔记,不支持保存图片、不支持保存图片、不支持保存图片,但支持以 Markdown 的方式引用图片。所以服务器端的压力就会小很多,成本低,才会更好的免费下去。

总结一下 Simplenote 的特点:

  • 尺寸小巧
  • 全平台支持(Win/macOS/Linux、iOS/Android)
  • Markdown 支持与预览
  • 置顶笔记
  • 多人实时协作
  • 回收站
  • 搜索
  • 标签支持(无分类)
  • 全屏注意力模式(桌面端)
  • 夜晚模式
  • 字体大小调节
  • PIN 锁(移动端)
  • 链接分享

多人实时协作功能非常赞,只需要在 tag 里添加对方邮箱就行了。之后对方就会在 Simplenote 中查看到笔记,并且双方的修改会实时可见,另外还会通过邮件收到这条笔记的预览。

如何让WordPress分类标签页支持置顶文章

WordPress内置的文章置顶功能只支持在首页让置顶文章在顶部显示,其他如分类页、标签页等所有archive存档页均不支持置顶文章在顶部显示。有时你需要将一些内容在分类、标签页下置顶,特别是Woocommerce网店应用中需推荐置顶一些产品到分类顶部就很有用。那么怎样才能让WordPress分类标签页也能置顶文章显示呢?参考wp-includes/query.php中首页置顶的代码,经修改后可以实行让分类、标签、作者及日期页等archive页面也能像首页一样在顶部显示所属内容的置顶文章。具体方法是将以下代码插入主题functions.php文件保存即可:

/*

让分类标签页支持置顶文章

代码来源: www.wpzxbj.com

*/

add_filter(\'the_posts\', \'putStickyOnTop\' );

function putStickyOnTop( $posts ) {

if(is_home() || !is_main_query() || !is_archive())

return $posts;

global $wp_query;

// 获取所有置顶文章

$sticky_posts = get_option(\'sticky_posts\');

if ( $wp_query->query_vars[\'paged\'] $sticky_posts ) );

foreach ( $stickies1 as $sticky_post1 ) {

// 判断当前是否分类页

if($wp_query->is_category == 1 && !has_category($wp_query->query_vars[\'cat\'], $sticky_post1->ID)) {

// 去除不属于本分类的置顶文章

$offset1 = array_search($sticky_post1->ID, $sticky_posts);

unset( $sticky_posts[$offset1] );

}

if($wp_query->is_tag == 1 && !has_tag($wp_query->query_vars[\'tag\'], $sticky_post1->ID)) {

// 去除不属于本标签的文章

$offset1 = array_search($sticky_post1->ID, $sticky_posts);

unset( $sticky_posts[$offset1] );

}

if($wp_query->is_year == 1 && date_i18n(\'Y\', strtotime($sticky_post1->post_date))!=$wp_query->query[\'m\']) {

// 去除不属于本年份的文章

$offset1 = array_search($sticky_post1->ID, $sticky_posts);

unset( $sticky_posts[$offset1] );

}

if($wp_query->is_month == 1 && date_i18n(\'Ym\', strtotime($sticky_post1->post_date))!=$wp_query->query[\'m\']) {

// 去除不属于本月份的文章

$offset1 = array_search($sticky_post1->ID, $sticky_posts);

unset( $sticky_posts[$offset1] );

}

if($wp_query->is_day == 1 && date_i18n(\'Ymd\', strtotime($sticky_post1->post_date))!=$wp_query->query[\'m\']) {

// 去除不属于本日期的文章

$offset1 = array_search($sticky_post1->ID, $sticky_posts);

unset( $sticky_posts[$offset1] );

}

if($wp_query->is_author == 1 && $sticky_post1->post_author != $wp_query->query_vars[\'author\']) {

// 去除不属于本作者的文章

$offset1 = array_search($sticky_post1->ID, $sticky_posts);

unset( $sticky_posts[$offset1] );

}

}

$num_posts = count($posts);

$sticky_offset = 0;

// Loop over posts and relocate stickies to the front.

for ( $i = 0; $i ID, $sticky_posts) ) {

$sticky_post = $posts[$i];

// Remove sticky from current position

array_splice($posts, $i, 1);

// Move to front, after other stickies

array_splice($posts, $sticky_offset, 0, array($sticky_post));

// Increment the sticky offset. The next sticky will be placed at this offset.

$sticky_offset++;

// Remove post from sticky posts array

$offset = array_search($sticky_post->ID, $sticky_posts);

unset( $sticky_posts[$offset] );

}

}

// If any posts have been excluded specifically, Ignore those that are sticky.

if ( !empty($sticky_posts) && !empty($wp_query->query_vars[\'post__not_in\'] ) )

$sticky_posts = array_diff($sticky_posts, $wp_query->query_vars[\'post__not_in\']);

// Fetch sticky posts that weren\'t in the query results

if ( !empty($sticky_posts) ) {

$stickies = get_posts( array(

\'post__in\' => $sticky_posts,

\'post_type\' => $wp_query->query_vars[\'post_type\'],

\'post_status\' => \'publish\',

\'nopaging\' => true

) );

foreach ( $stickies as $sticky_post ) {

array_splice( $posts, $sticky_offset, 0, array( $sticky_post ) );

$sticky_offset++;

}

}

}

return $posts;

}

如果你想让存档页也都显示全部置顶文章,那么就删掉16-49行的代码。如果不想在某分类页显示置顶文章,将第7行的

if(

改成:

// abc是分类名称

if ( is_category( \'abc\' ) ||

如果不想某标签页显示置顶文章,将第3行的

if(

改成:

// abc是标签名称

if ( is_tag( \'abc\' ) ||

如果不想某作者页显示置顶文章,将第 3 行的

if(

改成:

// abc是作者昵称

if ( is_author( \'abc\' ) ||

如果你在存档页使用WP_Query或query_posts来获取文章列表,又想让这些列表顶部显示置顶文章,可以把第7行代码中的以下代码删除(注意:可能会导致文章显示数量跟你设置的不一样):

|| !is_main_query()

如果你想给置顶文章添加样式,将以下代码添加到functions.php中,会给置顶文章添加一个名为 sticky 的class。具体的css代码,可以自定义:

add_filter(\'post_class\', \'addStickyClass\' ,10,3 );

function addStickyClass( $classes, $class, $post_id ){

if( is_sticky() && is_category() && !isset( $classes[\'sticky\'] ) ){

$classes[] = \'sticky\';

}

return $classes;

}

标签:

提交需求或反馈

Demand feedback