Controller is messing with my head

I have a custom post type called service and an associated controller for archives. I’ve done this many times on other projects, but it’s not happening on this one.

Here’s what I have:
cpt: service
taxes: service-category & service-tags
controller: archive-service.php
blade template: archive-service.blade.php
blade partial: content-single-service.blade.php (partial for single.blade.php)

Everything works as expected apart from the archive-service controller. I’ve also tested specific taxonomy templates and controllers and they work as expected.

I am missing something?

from the docs…

  • Copy index.blade.php to archive-gallery.blade.php for customizing the archive page for a custom post type registered as gallery

in there: @include('partials.content-'.get_post_type())

so presumably the template will be looking for partials/content-service.blade.php unless you’ve changed anything?

however it seems like you’ve got a different problem than that, if it’s the controller that’s not working?

I am on my phone so I can’t test anything but off the top of my head this may be a start: If by ”not working” you mean that the controller is not included at all, try changing the filename of the controller to ArchiveService.php and also make sure that there is a body css-class named ”archive-service-data” (at least I think that is what the body class should be).

Change this to ArchiveService.php
and ensure the class is named ArchiveService

Thanks, @codepuncher - I’ve already tried this - no joy.

The naming convention I’m using is sound (and works on other projects), the problem was me being a twonk and filtering out an essential <body> class.

@folbert YES!

This is the problem, I had a filter on the <body> class that removed the all important archive-service-data. Refined the filter and all is good.

Thank you so much - this was driving me insane, as I could see everything to do with the files was correct. Thank you!

FIX: the issue was self-inflicted - I had a filter on the body class that removed the archive-service-data class

Thanks, @jmp909 - the problem was in a completely different place, as described here.

This topic was automatically closed after 42 days. New replies are no longer allowed.