I am building a theme which Theme customizer changes colors, sizes, etc. and has also the option to choose a category and style that category specifically.
How can I display that category in the preview (only when the user is changing the corresponding options) instead of the default home/front page displayed by default?
EDIT
I can access the preview window with customize_preview_init, but I can not apply wp_redirect, which I guess could be a way.
If I understand you goal correctly, then will you a select inside the Customizer, there list the Categories and the User can use this for save in your theme settings.
If you will enhance the Customizer for categories, then use this class from this repo here. Include the file and enhacne the default class. You can easy implement a select for the categories of the install. Inside the readme of this repo are two links to gist with a example use, but for other class of the repo. I think is clear and the same way on all extensions for the Customizer.
Here’s an approach I used to show things to users while they are viewing the site through the Theme Customizer previewer:
It makes your templates a bit more messy but, as you’ve probably discovered, there isn’t much documentation/development on Theme customizer :/
Just add a javascript that activating only in live preview and redirect:
http://www.jquery4u.com/snippets/jquery-redirect-web-page/
as advanced solution, you can create asynchronously working js function with using wp.customize. You can inspect my theme http://theme.firmasite.com/ for example usage.
I ended up with this solution:
1.Require an extra file that will contain the hooks only in the theme preview
2.What I had to do is modify the query as I would normally do in the page, so just do it in the preview (inside preview.php):