In Genesis Slack chat, a user asked:
does anyone know how to create different widget areas between every 2-3 posts on a post page? I figured out how to create one that shows every so many posts BUT I am not sure how to create a new one so that every 2 posts its a different widget versus the same widget duplicated?
Below is a rough sketch of what the user wants:
There's an additional requirement in that while the posts are fixed width, the ad widgets should be full width with fixed width wraps.
- register 5 widget areas using a for loop: ad-1, ad-2, ad-3, ad-4 and ad-5.
- set the number of posts per page on the Posts page to 12 using `pre_get_posts`.
- create a template for the Posts page having the code to a) force full content i.e., no sidebar b) create a custom callback function to output the specified widget area c) display specific widget areas after 2nd, 4th, 6th, 8th and 10th posts using `genesis_after_entry` hook, switch case and built-in post counter.
- add CSS to remove the max-width of 1280px from Posts page's `.site-inner` and instead add it to the individual posts.
Note: This will work on the paginated pages as well.
While the tutorial has been written for Genesis Sample, it should work with a few adjustments in any Genesis theme.
Add the following in child theme's functions.php:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.