-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8b376e
commit 626bf5d
Showing
7 changed files
with
925 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
date: 2024-12-20 23:19 | ||
slug: 右侧边栏block 43粘性的设置 | ||
--- | ||
|
||
要实现当滚动到 block-43 时才启用 sticky 效果,如果要使用纯CSS实现,可以利用CSS的position: sticky和父元素的特性。以下是修改后的CSS: | ||
|
||
亲测可用;非常完美。 | ||
|
||
<!-- truncate --> | ||
|
||
```css | ||
.sidebar-main { | ||
position: relative; | ||
height: 100%; | ||
} | ||
|
||
#block-46 { | ||
position: relative; | ||
} | ||
|
||
#block-43 { | ||
position: sticky; | ||
top: 40px; | ||
max-height: calc(100vh - 40px); | ||
overflow-y: auto; | ||
padding: 10px; | ||
font-size: 0.9rem; | ||
border-left: 1px solid #dddddd; | ||
} | ||
|
||
#toc { | ||
margin: 0; | ||
padding: 0; | ||
list-style-type: none; | ||
} | ||
``` | ||
|
||
为何要父元素也一起设置?为父元素设置定位有两个重要原因: | ||
|
||
```css | ||
.sidebar-main { | ||
position: relative; /* 创建定位上下文 */ | ||
height: 100%; /* 确保有足够高度让子元素滚动 */ | ||
} | ||
``` | ||
|
||
1. 创建定位上下文: | ||
- position: sticky 的元素需要参照最近的具有滚动机制的祖先元素 | ||
- 设置父元素 position: relative 可以创建一个新的定位上下文 | ||
- 这样 sticky 元素就会在这个父容器内滚动,而不是相对于视口或其他容器 | ||
|
||
2. 确保滚动空间: | ||
- 如果父元素没有足够的高度,sticky 元素可能无法正常工作 | ||
- 设置 height: 100% 确保父容器有足够的高度来容纳滚动内容 | ||
|
||
如果不设置父元素的这些属性,sticky 效果可能会: | ||
- 无法找到正确的滚动参照物 | ||
- 在错误的位置停止粘附 | ||
- 完全不起作用 | ||
|
||
此方法为纯CSS。记得Astra设置里不要开启“启用置顶侧边栏”,否则与代码的CSS方案,就冲突了。 | ||
|
||
![image-20241220232139172](https://docu-1319658309.cos.ap-guangzhou.myqcloud.com/image-20241220232139172.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
date: 2024-12-21 07:48 | ||
slug: 前端页面显示is doc自定义字段是否为true | ||
--- | ||
|
||
发表文章后,如何查看是否确实有is doc这个自定义字段 | ||
|
||
![image-20241221075047228](https://docu-1319658309.cos.ap-guangzhou.myqcloud.com/image-20241221075047228.png) | ||
|
||
<!-- truncate --> | ||
|
||
好的,使用Astra的钩子来添加测试代码,以下是几个合适的位置: | ||
|
||
```php | ||
// 在文章内容前显示 | ||
add_action('astra_content_before', function() { | ||
if(is_single() && current_user_can('administrator')) { | ||
echo '<div style="background: #f0f0f0; padding: 10px; margin: 10px 0;">'; | ||
echo '文章ID: ' . get_the_ID() . '<br>'; | ||
echo 'is_doc值: ' . get_post_meta(get_the_ID(), 'is_doc', true); | ||
echo '</div>'; | ||
} | ||
}); | ||
|
||
// 或者在文章标题后显示 | ||
add_action('astra_entry_content_before', function() { | ||
if(is_single() && current_user_can('administrator')) { | ||
echo '<div style="background: #f0f0f0; padding: 10px; margin: 10px 0;">'; | ||
echo '文章ID: ' . get_the_ID() . '<br>'; | ||
echo 'is_doc值: ' . get_post_meta(get_the_ID(), 'is_doc', true); | ||
echo '</div>'; | ||
} | ||
}); | ||
|
||
// 或者在文章内容后显示 | ||
add_action('astra_content_after', function() { | ||
if(is_single() && current_user_can('administrator')) { | ||
echo '<div style="background: #f0f0f0; padding: 10px; margin: 10px 0;">'; | ||
echo '文章ID: ' . get_the_ID() . '<br>'; | ||
echo 'is_doc值: ' . get_post_meta(get_the_ID(), 'is_doc', true); | ||
echo '</div>'; | ||
} | ||
}); | ||
``` | ||
|
||
选择一个钩子使用即可,建议使用`astra_content_before`,这样显示在最明显的位置。测试完成后记得删除代码。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
date: 2024-12-21 06:10 | ||
slug: 善用管理员可见的wp_footer来调试 | ||
--- | ||
|
||
|
||
|
||
输出到管理员可见的wp-footer,可以用来调试,很方便啊。举几个例子说明 | ||
|
||
<!-- truncate --> | ||
|
||
以下是几个实用的调试输出示例,都添加到 functions.php 中: | ||
|
||
1. 检查当前页面模板: | ||
```php | ||
function debug_template_info() { | ||
if ( current_user_can( 'administrator' ) ) { | ||
echo '<!-- Debug Template Info -->'; | ||
echo '<div style="background:#f1f1f1;padding:10px;margin:20px;border:1px solid #ddd;">'; | ||
echo 'Template File: ' . get_page_template_slug(); | ||
echo '<br>Post Type: ' . get_post_type(); | ||
echo '<br>Page Type: ' . (is_single() ? 'Single' : (is_page() ? 'Page' : 'Other')); | ||
echo '</div>'; | ||
} | ||
} | ||
add_action( 'wp_footer', 'debug_template_info' ); | ||
``` | ||
|
||
2. 显示当前使用的钩子: | ||
```php | ||
function debug_current_hooks() { | ||
if ( current_user_can( 'administrator' ) ) { | ||
global $wp_actions; | ||
echo '<!-- Debug Hooks -->'; | ||
echo '<div style="background:#f1f1f1;padding:10px;margin:20px;border:1px solid #ddd;">'; | ||
echo 'Current Active Hooks:<br>'; | ||
foreach ( $wp_actions as $action => $count ) { | ||
echo $action . ' (' . $count . ')<br>'; | ||
} | ||
echo '</div>'; | ||
} | ||
} | ||
add_action( 'wp_footer', 'debug_current_hooks' ); | ||
``` | ||
|
||
3. 查看Astra主题设置: | ||
```php | ||
function debug_astra_settings() { | ||
if ( current_user_can( 'administrator' ) ) { | ||
echo '<!-- Debug Astra Settings -->'; | ||
echo '<div style="background:#f1f1f1;padding:10px;margin:20px;border:1px solid #ddd;">'; | ||
echo 'Astra Settings:<br>'; | ||
$theme_options = get_option( 'astra-settings' ); | ||
echo '<pre>'; | ||
print_r( $theme_options ); | ||
echo '</pre>'; | ||
echo '</div>'; | ||
} | ||
} | ||
add_action( 'wp_footer', 'debug_astra_settings' ); | ||
``` | ||
|
||
4. 查看当前页面的查询: | ||
```php | ||
function debug_current_query() { | ||
if ( current_user_can( 'administrator' ) ) { | ||
global $wp_query; | ||
echo '<!-- Debug Query -->'; | ||
echo '<div style="background:#f1f1f1;padding:10px;margin:20px;border:1px solid #ddd;">'; | ||
echo 'Current Query:<br>'; | ||
echo '<pre>'; | ||
print_r( $wp_query->query ); | ||
echo '</pre>'; | ||
echo '</div>'; | ||
} | ||
} | ||
add_action( 'wp_footer', 'debug_current_query' ); | ||
``` | ||
|
||
5. 显示已加载的脚本和样式: | ||
```php | ||
function debug_enqueued_scripts() { | ||
if ( current_user_can( 'administrator' ) ) { | ||
global $wp_scripts, $wp_styles; | ||
echo '<!-- Debug Enqueued Scripts/Styles -->'; | ||
echo '<div style="background:#f1f1f1;padding:10px;margin:20px;border:1px solid #ddd;">'; | ||
echo 'Enqueued Scripts:<br>'; | ||
foreach( $wp_scripts->queue as $script ) { | ||
echo $script . '<br>'; | ||
} | ||
echo '<br>Enqueued Styles:<br>'; | ||
foreach( $wp_styles->queue as $style ) { | ||
echo $style . '<br>'; | ||
} | ||
echo '</div>'; | ||
} | ||
} | ||
add_action( 'wp_footer', 'debug_enqueued_scripts' ); | ||
``` | ||
|
||
这些调试输出都: | ||
1. 仅对管理员可见 | ||
2. 添加在页面底部 | ||
3. 使用容易识别的HTML注释 | ||
4. 有基本的样式便于阅读 | ||
5. 可以同时使用多个 | ||
|
||
使用时注意: | ||
- 只在开发环境中使用 | ||
- 正式环境记得删除或注释掉 | ||
- 可以根据需要修改样式让显示更醒目 | ||
- 可以添加更多你需要的信息 |
Oops, something went wrong.