article-structure-data
1 week ago
auto-eyecatch
1 year ago
block-editor-panels
1 month ago
call-to-action
6 days ago
child-page-index
2 months ago
contact-section
6 days ago
css-customize
7 months ago
default-thumbnail
8 months ago
font-awesome
4 years ago
google_analytics
1 year ago
icon-accessibility
1 year ago
nav-menu-class-custom
1 year ago
noindex
1 year ago
other-widget
6 days ago
page-exclude-from-list-pages
2 months ago
page-list-ancestor
2 months ago
pagetop-btn
1 week ago
post-type-manager
1 month ago
promotion-alert
7 months ago
related_posts
4 weeks ago
sitemap-page
2 months ago
smooth-scroll
1 year ago
sns
6 days ago
template-tags
4 weeks ago
vk-breadcrumb
4 years ago
vk-css-optimize
1 year ago
vk-google-tag-manager
1 year ago
website-structure-data
1 year ago
wp-title
7 months ago
add-body-class.php
4 weeks ago
add_archive_loop_before_widget_area.php
1 year ago
add_menu_to_block_reuse.php
7 months ago
add_plugin_link_to_adminbar.php
1 year ago
common-block.php
1 year ago
contactform7-asset-optimize.php
1 year ago
disable-dashbord.php
1 year ago
disable-emojis.php
1 year ago
disable-xml-sitemap.php
1 year ago
disable_ping-back.php
6 years ago
footer-copyright-change.php
1 year ago
insert-ads.php
1 year ago
meta-description.php
1 year ago
add_archive_loop_before_widget_area.php
101 lines
| 1 | <?php |
| 2 | function veu_set_archive_loop_before_widget_area() { |
| 3 | |
| 4 | // � |
| 5 | �開されている投稿タイプを呼び出し |
| 6 | $postTypes = get_post_types( array( 'public' => true ) ); |
| 7 | // 固定ページはアーカイブないので削除 |
| 8 | unset( $postTypes['page'] ); |
| 9 | |
| 10 | foreach ( $postTypes as $postType ) { |
| 11 | |
| 12 | // Get post type name |
| 13 | /*-------------------------------------------*/ |
| 14 | $post_type_object = get_post_type_object( $postType ); |
| 15 | if ( $post_type_object ) { |
| 16 | |
| 17 | // Set post type name |
| 18 | $postType_name = esc_html( $post_type_object->labels->name ); |
| 19 | |
| 20 | // Set post type widget area |
| 21 | register_sidebar( |
| 22 | array( |
| 23 | 'name' => sprintf( __( 'Post type archive before loop (%s)', 'vk-all-in-one-expansion-unit' ), $postType_name ), |
| 24 | 'id' => $postType . '-archive-loop-before', |
| 25 | 'description' => '', |
| 26 | 'before_widget' => '<aside class="widget %2$s" id="%1$s">', |
| 27 | 'after_widget' => '</aside>', |
| 28 | 'before_title' => '<h2 class="widget-title">', |
| 29 | 'after_title' => '</h2>', |
| 30 | ) |
| 31 | ); |
| 32 | } // if( $post_type_object ){ |
| 33 | } // foreach ($postTypes as $postType) { |
| 34 | } |
| 35 | add_action( 'widgets_init', 'veu_set_archive_loop_before_widget_area' ); |
| 36 | |
| 37 | function veu_display_archive_loop_before_widget_area( $query ) { |
| 38 | |
| 39 | $loop_action_point = veu_get_loop_before_widget_action_point(); |
| 40 | if ( veu_get_loop_before_widget_action_point() === 'loop_start' ) { |
| 41 | // $loop_action_point を loop_start にする場合メインクエリ以外の場所に出ないように終了 |
| 42 | if ( ! $query->is_main_query() ) { |
| 43 | return; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if ( ! is_post_type_archive() && ! is_home() && ! is_front_page() ) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | if ( is_home() ) { |
| 52 | $post_type = 'post'; |
| 53 | } |
| 54 | |
| 55 | global $wp_query; |
| 56 | |
| 57 | if ( ! empty( $wp_query->query_vars['post_type'] ) ) { |
| 58 | $post_type = $wp_query->query_vars['post_type']; |
| 59 | } |
| 60 | |
| 61 | if ( empty( $post_type ) ) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | if ( ! empty( $wp_query->posts ) ) { |
| 66 | // 2ページ目以外は非表示 |
| 67 | if ( get_query_var( 'paged', 0 ) !== 0 ) { |
| 68 | return; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // ※ get_post_type() は該当記事がない場合に投稿タイプが取得できないため |
| 73 | $widget_area = $post_type . '-archive-loop-before'; |
| 74 | if ( is_active_sidebar( $widget_area ) ) { |
| 75 | dynamic_sidebar( $widget_area ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * ウィジェットエリアを追加するアクションフックポイント |
| 81 | */ |
| 82 | function veu_get_loop_before_widget_action_point() { |
| 83 | $template = wp_get_theme()->Template; |
| 84 | $loop_action_point = 'loop_start'; |
| 85 | if ( $template == 'katawara' ) { |
| 86 | // Katawaraの場合 |
| 87 | $loop_action_point = 'katawara_loop_before'; |
| 88 | } elseif ( $template == 'lightning' || $template == 'lightning-pro' ) { |
| 89 | // Lightningの場合 |
| 90 | $loop_action_point = 'lightning_loop_before'; |
| 91 | } |
| 92 | return $loop_action_point; |
| 93 | } |
| 94 | |
| 95 | function veu_loop_before_widget_run() { |
| 96 | $loop_action_point = veu_get_loop_before_widget_action_point(); |
| 97 | add_action( $loop_action_point, 'veu_display_archive_loop_before_widget_area' ); |
| 98 | } |
| 99 | |
| 100 | add_action( 'after_setup_theme', 'veu_loop_before_widget_run', 11 ); |
| 101 |