We're merging with GenerateBlocks! Learn more here.

[Resolved] Use Static Pages as Category Archives

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Use Static Pages as Category Archives

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #10428
    Ericka
    Participant

    Hi!
    I follow the instructions in “Use Static Pages as Category Archives” documentation. And everything in good! But im wondering:

    – Do I have to NOINDEX my category pages?
    – Do I have to make a redirection?
    – Is there gonna be duplicate content?

    #10440
    Tom
    Keymaster

    Hi there,

    I believe the code in that article does the redirection for you. The old category pages shouldn’t be accessible if you type them into your address bar.

    However, if you’re worried, it doesn’t hurt to set up a 301 redirect from the old category archives to the new pages. This will make sure all three of those points are dealt with.

    #10446
    Ericka
    Participant

    Ok thanks!!

    #10459
    Tom
    Keymaster

    No problem ๐Ÿ™‚

    #10525
    Ericka
    Participant

    Hi! Is me again!

    Is there a way to exclude some categories when the function is active? I dont want all my categories to be static pages, just the “important” ones for SEO purposes.

    #10527
    Tom
    Keymaster

    Try this:

    add_filter('request', function( array $query_vars ) {
        if ( is_admin() ) {
            return $query_vars;
        }
    
        $targets = array(
            'My name here',
            'Another',
            'One More Name',
        );
    
        if ( isset( $query_vars['category_name'] ) && in_array( $query_vars['category_name'], $targets ) ) {
            $pagename = $query_vars['category_name'];
    
            $query_vars = array( 'pagename' => "$pagename" );
        }
    
        return $query_vars;
    } );

    Then adjust the names of the categories you want to target in the $targets array.

    #10533
    Ericka
    Participant

    You mean here:

    $targets = array(
    ‘My name here’,
    ‘Another’,
    ‘One More Name’,
    );

    But how I adjust the names of the categories? For example, if I have a category with this URL: /category/books/ and a page just: /books/, how i put the name in the code? ๐Ÿ˜€

    #10540
    Tom
    Keymaster

    If your category name is “Books”, you would do this:

    $targets = array(
        'Books',
    );
    #10543
    Ericka
    Participant

    Ok perfect!! Thanks again ๐Ÿ™‚

    #10558
    Tom
    Keymaster

    You’re welcome ๐Ÿ™‚

    #28750
    TWarrior
    Participant

    Hello,

    This is not working for me:

    add_filter('request', function( array $query_vars ) {
        if ( is_admin() ) {
            return $query_vars;
        }
    
        $targets = array(
            'Biblio',
        );
    
        if ( isset( $query_vars['category_name'] ) && in_array( $query_vars['category_name'], $targets ) ) {
            $pagename = $query_vars['category_name'];
    
            $query_vars = array( 'pagename' => "$pagename" );
        }
    
        return $query_vars;
    } );

    – I have a “Biblio” page and a “Biblio” category.
    – If I remove the “&& in_array( $query_vars[‘category_name’], $targets )” code (using the default code in https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/ ) It is works perfectly.

    What am I missing?

    #28753
    TWarrior
    Participant

    I have make it works only if:

    1. I use the slug “biblio”, not the name “Biblio”.
    AND
    2. The category has no “Parent Category”

    But i need the parent category…

    #28924
    elvin
    Moderator

    Hi there,

    category_name takes the slug, not the actual Label/name.
    https://developer.wordpress.org/reference/classes/wp_query/#category-parameters

    โ€œBiblioโ€ is a label/name. โ€œbiblioโ€ is a slug, that’s why it works.

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.