Site logo

Archived topic

Show posts on static frontpage + use static pages as Category Archives

30 replies · Started by Patryk on March 12, 2020

Viewing posts 16–30 of 31

Not sure - i have asked Tom to take a look at the issue.

That's good because i think that there will be more people interested in.

Strange, haven't seen people have this issue with the code before. There's likely something up with your rewrite rules.

You might be able to prevent it with this:

add_filter('request', function( array $query_vars ) {
    if ( is_admin() ) {
        return $query_vars;
    }

    if ( isset( $query_vars['category_name'] ) && is_archive() ) {
        $pagename = $query_vars['category_name'];

        $query_vars = array( 'pagename' => "$pagename" );
    }

    return $query_vars;
} );

It works! Thank you so much.

Oh no. Just realize that im wrong. Now it use the categorie archives instead of static pages...

Any other idea?

Must be something weird going on with your setup. What do you have set for permalinks in "Settings > Permalinks"?

Hi,

my permalink setup:
/%category%/%postname%/

And my menu setup:
individual link as main menu item and category as sub menu item.

Thanks.

What if you just use the standard %postname% permalinks? Any difference?

Hi Tom, that‘s it!
Any ideas to get it with the other permalink structure? Thanks again.

Hmm, we could try debugging in the code.

For example:

add_filter('request', function( array $query_vars ) {
    if ( is_admin() ) {
        return $query_vars;
    }

    var_dump($query_vars['category_name']);

    return $query_vars;
} );

What does that output above the header when viewing category pages?

Hi Tom,

i switch permalinks to /%category%/%postname%/

The output for the category page is the same as in the post:
- string(6) “rezept“ in the category Rezept
- string(8) “hausarzt“ in the category Hausarzt

Can we try this now?:

add_filter('request', function( array $query_vars ) {
    if ( is_admin() ) {
        return $query_vars;
    }

    if ( isset( $query_vars['category_name'] ) && is_archive() ) {
        $pagename = $query_vars['category_name'];

        var_dump($pagename);

        //$query_vars = array( 'pagename' => "$pagename" );
    }

    return $query_vars;
} );

Does it output anything?

Hi Tom,

no nothing.

I'm assuming the action runs too early for is_archive() to work, that's a shame.

I'm not really sure what to do here, unfortunately.

My last guess would be to do this, but it's just a guess:

add_filter('request', function( array $query_vars ) {
    if ( is_admin() ) {
        return $query_vars;
    }

    if ( isset( $query_vars['category_name'] ) && ! isset( $query_vars['p'] ) ) {
        $pagename = $query_vars['category_name'];

        $query_vars = array( 'pagename' => "$pagename" );
    }

    return $query_vars;
} );

category_name should only be set when viewing a category, but I guess having it in your permalinks makes it so it's always true.

Ok it does not work. But no problem. I switch back to the other permalink and than its fine for me. But thank you very much for your assistance.

This archived topic is closed to new replies.