• discoveryowarinakita

    (@discoveryowarinakita)


    PHP初心者です。タイトルの重複に困っています。

    ①/category/講座/
    ②/category/講座/訪問/

    ↑のようにタイトルの重複となってしまっています。
    カテゴリはインデックスさせている状態です。
    ※カテゴリはノーインデックスにするつもりはないです。

    ■やりたいこと
    ①はそのままですが、
    ②の場合は講座のリンクをなくして訪問だけのリンクで
    カテゴリを作成すれば重複がなくなると思うのですが、

    この場合、どのようにすればできるのか教えてほしいです。

    現在の記述は以下です。

    add_shortcode(‘postonly’, ‘st_postsc_func’);

    if ( !function_exists( ‘st_categorysc_func’ ) ) {
    function st_categorysc_func( $arg, $content = null ) {
    $atts = shortcode_atts(
    array(
    ‘cat’ => ‘0’,
    ),
    $arg
    );

    $atts[‘cat’] = ( trim( $atts[‘cat’] ) !== ” ) ? $atts[‘cat’] : ‘0’;

    $is_home_or_front_page = is_main_query() && ( get_the_ID() === get_queried_object_id() ) &&
    ( is_home() || is_front_page() );

    if ($is_home_or_front_page) {
    return ”;
    }

    $cat_ids = explode( ‘,’, $atts[‘cat’] );
    $cat_ids = array_reduce(
    $cat_ids,
    function ( $new_cat_ids, $cat_id ) {
    $cat_id = trim( $cat_id );

    if ( preg_match( ‘/\A[0-9]+\z/’, $cat_id ) ) {
    $new_cat_ids[] = (int) $cat_id;
    }

    return $new_cat_ids;
    },
    array()
    );
    $cat_ids = array_unique( $cat_ids );

    if ( !in_array( 0, $cat_ids, true ) && !in_category( $cat_ids ) ) {
    return ”;
    }

    return ‘<div>’ . $content . ‘</div>’;
    }
    }
    add_shortcode( ‘catonly’, ‘st_categorysc_func’ );

    if ( !function_exists( ‘st_trim_excerpt’ ) ) {
    function st_trim_excerpt( $text = ” ) {
    if ( $text !== ” ) {
    return $text;
    }

    $text = get_the_content( ” );
    $text = apply_filters( ‘the_content’, $text );
    $text = str_replace( ‘]]>’, ‘]]>’, $text );

    $excerpt_length = apply_filters( ‘excerpt_length’, 55 );

    $excerpt_more = apply_filters( ‘excerpt_more’, ‘ ‘ . ‘[…]’ );
    $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );

    return $text;
    }
    }
    add_filter( ‘get_the_excerpt’, ‘st_trim_excerpt’, 9 );

    何卒、よろしくお願い致します。

    ※テンプレートはアフィンガー4を使っています。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • hide

    (@hideokamoto)

    /category/講座/
    /category/講座/訪問/

    この2つのURLを

    /category/
    /category/訪問/

    にしたいということでしょうか?

    特に記事タイトルが重複しているようには見えませんが、
    もう少し具体的に状況を教えて頂けますと助かります。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「PHP初心者です。タイトルの重複に困っています。」には新たに返信することはできません。