[ 解決済 ] アーカブページの選択方法

VWSとは フォーラム バグ報告と提案 [ 解決済 ] アーカブページの選択方法

[ 解決済 ] アーカブページの選択方法

  • このトピックには16件の返信、2人の参加者があり、最後にkomori0321により3年、 4ヶ月前に更新されました。
2件の投稿を表示中 - 16 - 17件目 (全17件中)
  • 投稿者
    投稿
  • #46060

    これでよろしくお願いいたします。

    function my_set_archive_loop_before_widget_area(){
    
        // 公開されている投稿タイプを呼び出し
        $postTypes = get_post_types( array( 'public' => true ) );
        // 固定ページはアーカイブないので削除
        unset( $postTypes['page'] );
    
        foreach ( $postTypes as $postType ) {
    
            // Get post type name
            /*-------------------------------------------*/
            $post_type_object = get_post_type_object( $postType );
            if ( $post_type_object ) {
    
                // Set post type name
                $postType_name = esc_html( $post_type_object->labels->name );
    
                // Set post type widget area
                register_sidebar(
                    array(
                        'name'          => sprintf( __( 'Archive page loop before (%s)', 'lightning-pro' ), $postType_name ),
                        'id'            => $postType . '-archive-loop-before',
                        'description'   => '',
                        'before_widget' => '<aside class="widget %2$s" id="%1$s">',
                        'after_widget'  => '</aside>',
                        'before_title'  => '<h2 class="widget-title">',
                        'after_title'   => '</h2>',
                    )
                );
            } // if( $post_type_object ){
    
        } // foreach ($postTypes as $postType) {
    
    }
    add_action( 'widgets_init', 'my_set_archive_loop_before_widget_area' );
    
    function my_display_archive_loop_before_widget_area( $query ){
    
        if ( ! is_archive() && ! is_home() ){
            return;
        }
    
        global $wp_query;
        
        $post_type_info = lightning_get_post_type();
    
        $post_type = $post_type_info['slug'];
    
        if ( $post_type ) {
            // ※ get_post_type() は該当記事がない場合に投稿タイプが取得できないため
            $widget_area = $post_type . '-archive-loop-before';
            if ( is_active_sidebar( $widget_area ) ) {
                dynamic_sidebar( $widget_area );
            }
        }
    
    }
    // Lightningの場合
    $loop_action_point = 'lightning_loop_before';
    add_action( $loop_action_point, 'my_display_archive_loop_before_widget_area' );
    #46067

    komori0321
    参加者

    石川様

    お世話になります
    今回の修正で、希望通リの動作になりました
    お手数をおかけいたしました
    ありがとうございました

2件の投稿を表示中 - 16 - 17件目 (全17件中)
  • このトピックに返信するにはログインが必要です。