[Support request] Custom Category Pages

Home Forums Support [Support request] Custom Category Pages

Home Forums Support Custom Category Pages

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1110259
    Vish

    Hi Tom

    So, I have been digging around ways to make custom category pages. Figured out that it can be done with WP Show Posts (I have the Pro version too).

    I came across this help doc: Use Static Pages as Category Archives

    Now, If I follow the above method, I would have to make static category pages for all my categories. The problem is I have too many categories and it does not seem feasible. I want the above method to work for only one category. Is there a way to do it by hardcoding the category name or something?

    #1110735
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this:

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

    It will only work if the page actually exists.

    #1110980
    Vish

    Tom

    It’s not working. Maybe I am doing something wrong? Here’s what I did:

    This is my category URL: https://randomdomain.com/category/generatepress-themes
    I have created a page with WP Show Posts shortcode. This is the URL: https://randomdomain.com/generatepress-themes

    I tweaked your code to add the category name like below and added it as a snippet using Code Snippets.

    add_filter('request', function( array $query_vars ) {
        if ( is_admin() ) {
            return $query_vars;
        }
    
        if ( isset( $query_vars['generatepress-themes'] ) ) {
            $pagename = $query_vars['generatepress-themes'];
    
            if ( get_page_by_title( $pagename ) ) {
                $query_vars = array( 'pagename' => "$pagename" );
            }
        }
    
        return $query_vars;
    } );

    The only change I made is replacing the category_name with generatepress-themes

    #1111395
    Tom
    Lead Developer
    Lead Developer

    My code is actually complete – no need to change it at all ๐Ÿ™‚

    #1122941
    Vish

    My bad! I used your code as-is without any changes and it still didn’t work.

    Here’s some more information:
    My Category Page URL:https://www.example.com/category/wordpress-themes
    My Normal Page URL:https://www.example.com/wordpress-themes

    I simply copy/pasted your code to code snippets and set it to run everywhere.

    Kindly let me know if I am doing something wrong. ๐Ÿ™‚

    #1123099
    Tom
    Lead Developer
    Lead Developer

    Strange, just to confirm, does this code work for you?: https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/

    I know it’s meant for all categories, but I just want to make sure the filter is executing.

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