Here’s a zip file of the php code to define a token that creates a small table showing all donations made by any contact during the previous calendar year, including donations made by a spouse. If there is no spouse, the spouse names are not included in the token’s output.
The token does it’s own queries to find contributions and will produce the same table if called for either spouse. It can be used to generate individual thank-you letters (or emails) directly from a contact summary page, or multiple letters/emails from the results of a contact search.
I added the above code to my WordPress child theme’s functions.php. The exact method for registering the hooks is slightly different for non-wordpress systems.
Sample output when the contact has a spouse:
Sample output when the contact has no spouse: