[Support request] Replacing blogroll on a category page with a single page

Home Forums Support Replacing blogroll on a category page with a single page

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1082198
    Mark

    Hi,

    I want to build out category pages using ‘content sections’, as if those category pages were a standard page (or post.)

    I used to do something similar on an older theme I had, where I would create category-categorslug.php files (where categoryslug is the URL of the category) and drop this into the child theme.

    In the category-categoryslug.php I would copy the category.php code, and replace the loop with with code that showed th content of a page.

    Is it possible to do this in Generatepress? So I can show a page built using ‘content sections’ instead of the loop on a category archive page?

    If so, could you create the file I would need to drop into my child theme, that would perform the following:

    • Replace category archive with name and slug ‘recipes’ (file: category-recipes.php)
    • Have the loop code removed, so no blogroll shows on the category page
    • Have code inserted instead of where the loop is, that pulls the ‘content’ for page ID=12345 instead.
    • Is this possible?

      Thanks,
      Mark.

    #1082703
    David
    Staff
    Customer Support

    Hi there,

    sounds awfully complicated, maybe the filter Tom provides here would be an easier solution:

    https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/

    #1082869
    Mark

    “sounds awfully complicated” LMAO…yes, maybe. Just a simple ‘copy paste’ though really.

    Anyway, I tried the filter you suggested. It works, but you then have to replace every single category page with a page of the slug. Can that filter be adapted to replace a single category, with a single page? Or perhaps code to swap 5 categories with 5 pages?

    I have 22 categorys, and do not need this for every one,some can stay the standard category archive page.

    #1085167
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    This should do it:

    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;
    } );

    That will only use the static page if it exists.

    Let me know 🙂

    #1093807
    Mark

    Hi Tom,

    That’s great, thank you.

    Sorry for the delay in a response, super busy with ‘life in general’ at the moment. I’ll get to testing this on Sunday, my next work day.

    I do have another question though…not sure if should add here or in the WP Show posts forum?:

    Is there a way to improve how the last items in a WP Show Posts grid display when the lists isn’t full?

    What i mean is: let’s say you have it set to display 9 posts in 3 columns, but there are only 7 posts. What happens now is, you get 3 top row, 3 middle row, and 1 last row, aligned left. It just doesn’t look ‘polished.’

    is there a way to either have:

    Top row 3 posts, middle row 3 posts, bottom row one post, but centred? Or even ‘full screen width’?
    or
    Top row 1 post centred or ‘full screen width’ then middle row 3 posts, bottom row 3 posts.

    Same if there were only 8 posts (for example when you next post one in that category:

    It currently shows 3 top row, 3 middle, 2 bottom left aligned. Could you have two bottom row, centre aligned, or two at 50% column, etc.

    Right now, it just looks like the site wasn;t thoughtfully designed. So you have to omit a post, or create 2 post lists with different column numbers. But then if you post a new post to a category you then have to go back in and juggle the lists around to fit again.

    #1094647
    David
    Staff
    Customer Support

    Hi there,

    tricky one – but if you have a link to share where the ‘issue’ is i can take a look at what we do with flexbox.

    #1099251
    Mark

    Hi David,

    it’s OK, I worked around it by juggling post numbers and what not, doesn;t look so bad now.

    One potentially big issue though: Using toms code above to replace a category with a page, does literally that – but with a not good twist.

    With all categories and pages set to ‘index, follow’, I have duplicate URLs in my XML sitemaps for the category pages and pages with the same URLs.

    I can set the categories to ‘noindex’ and have only pages in the XML sitemap, but then my sitemaps will not show the structure of my site, it will show all pages and zero categories.

    If I set the pages to noindex, then of course they are noindex and not in the sitemap.

    Ideally, I need the category pages in the index, and in the xml sitemap,. NOT the pages that replace them.

    Therefore the solution as it stands, with the WP filter showing pages instead of categories for the same URL, really messes with the XML sitemaps.

    So it looks like I’m back to my original query: Can we hack the category page file, to show the contents of a page instead of the loop? I’ve done this on other sites, just not sure how to with Generatepress.

    This would allow me to noindex the pages, 301 them to the category pages, have the content displaying on the category pages and my XML sitemaps would be correct.

    Mark.

    #1099285
    Mark

    Hold that thought, think i found a solution, Number 4 in this post, the filter to remove xml sitemap entries:

    https://kb.yoast.com/kb/sitemap-shows-excluded-posts-pages/

    This means I can leave both pages and categories set to ‘index’, remove the pages from sitemap using an array of page IDs in the yoast filter, the xml sitemap shows the urls as categories, on the live site they are set to index, and between sitemap and breadcrumbs my ‘structure’ is now correct, and I do not have a ton of pages either accessible or in the sitemap, they show as categories.

    Job done…I think :p

    #1100093
    Tom
    Lead Developer
    Lead Developer

    Glad you found a solution! 🙂

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