[Resolved] [GPP 2.0 beta] Content template not working with static archives

Home Forums Support [Resolved] [GPP 2.0 beta] Content template not working with static archives

Home Forums Support [GPP 2.0 beta] Content template not working with static archives

  • This topic has 9 replies, 2 voices, and was last updated 3 years ago by David.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1723662
    George

    I am using this coode to set static pages as category archives:

    //Use Static Pages as Category Archives
    add_filter('request', function( array $query_vars ) {
        if ( is_admin() ) {
            return $query_vars;
        }
    
        if ( isset( $query_vars['category_name'] ) ) {
            $pagename = $query_vars['category_name'];
    
            $query_vars = array( 'pagename' => "$pagename" );
        }
    
        return $query_vars;
    } );

    The template is not being displayed on the static category page, though. It just displays static content. When I deactivate the code, the template is displayed normally. Is there a way around it?

    #1724461
    David
    Staff
    Customer Support

    Hi there,

    what is the Content Template being used for ? Is it to display the archive loop ?

    #1725114
    George

    Yes.

    #1725896
    David
    Staff
    Customer Support

    The templates only have a single loop to display the_content. So it’s either an archive loop or its a page content loop…. not both.

    Aside of writing your own custom templates, the alternative would be to hook in the Page content that would need to be pulled in from a custom post type / custom fields.

    #1725917
    George

    But I’ve set my category pages to be static pages so, in theory, it should work, no? Can I at least exclude a certain category from the code provided in the first post?

    #1726048
    David
    Staff
    Customer Support

    Nope – that code is changing the category archive request to a static page – the archive template which has the_loop for displaying the archives is not being loaded.

    To exclude a category from static pages – you could change the first condition ie.

    if ( is_admin() ) {

    to include a is_category template tag eg.

    if ( is_admin() || is_category('your-category-slug') ) {

    #1726085
    George

    Hmmm. I tried your suggestion but I am getting a 404 error on the selected category. I’ve also deleted the original Travel static category page and resaved my permalinks.

    add_filter('request', function( array $query_vars ) {
        if ( is_admin() || is_category('travel') ) {
            return $query_vars;
        }
    
        if ( isset( $query_vars['category_name'] ) ) {
            $pagename = $query_vars['category_name'];
    
            $query_vars = array( 'pagename' => "$pagename" );
        }
    
        return $query_vars;
    } );
    #1726144
    David
    Staff
    Customer Support

    Hmmm… not sure on this – you could try removing that condition and add a secondary condition to the $query_var addition:
    e.g

    if ( isset( $query_vars['category_name'] ) ) {
      $pagename = $query_vars['category_name'];
      if ( $pagename != 'your-category-slug') {
        $query_vars = array( 'pagename' => "$pagename" );
      }
    }
    #1726427
    George

    Perfect, that did the trick!

    Thanks, David.

    #1726444
    David
    Staff
    Customer Support

    Great – glad to hear that!!

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