Here is an easy solution for extending your Raspberry Pi's GPIO capabilities. This is a 40-pin FPC to Straight 2x20 IDC Female Socket Header Adapter
Use this adapter, which will act as an extender for all 40 pins to give you a streeeeetch. Simply plug the socket side into the Raspberry Pi. Then, keeping an eye where Pin 1 is, insert your FPC ribbon cable into the 40-pin flex connector.
You can use any 40-pin 0.5mm FPC with 'A-B' connections. If you want to extend the FPC, a 40-pin extender can be snapped on. Finally, you can use a matching adapter board to tack on your HAT or bonnet of choice on the other end
Note that some HATs, like the Sense HAT or Bonnets with a slim connector on the bottom will need/benefit from adding a socket 'riser' / 'lifter' to the HAT to give the cable more connector body to grip onto. Take a look at the HAT or accessory you're trying to extend. If there isn't a chunky connector on the bottom of the HAT, pick up a riser!
PCB dimensions: 54.3mm x 26mm x 11.8mm