How to apply a custom template to product listing view if the page name is NOT product_list

It appears to me that you can only use custom templates for the product listing (and a few other things) if the pagename is EXACTLY product_list.
Not even the default slugs are taken into account as it seems.
Apparently here it checks for a hardcoded pagename:
if ($wp_query->query_vars['pagename'] == 'product_list')

Whereas the main store page at least looks for the slug that was defined in the settings.
//load proper theme for main store page
$slugs = $this->get_setting('slugs');
if ($wp_query->query_vars['pagename'] == $this->get_setting('slugs->store')) {

I'm not exactly eager to modify code in the core of the Marketpress plugin as such changes would be lost at the next update again.

Am I simply overlooking something or is this really a severe difference between documentation and the real code?

  • Mastacheata

    Please see the themeing readme on how the template structure works.

    Did that. It says I need to create a file called mp_productlist.php in my theme and then marketpress will apply that as the template file for the product listing.

    Well, guess what? It does that. But only if the page with the mp_productlist shortcode matches the right query string part.
    If I choose to name my product listing page differently, Marketpress doesn't even look for custom templates (as the stuff looking if custom templates are present is INSIDE the conditional section mentioned before)
    I can even prove that by adding some nasty debug output inside that conditional section of marketpress.php and it will NEVER appear unless the page name matches product_list.

    Apparently the rewrite rules are not applied correctly If I create that product list page by hand.

  • Aaron

    I'm confused at what shortcode has to do with the templates? You do not use shortcodes in custom template files, you have to use the proper template function or your own custom loop using the template functions from template-functions.php. MP uses virtual pages, that all use the page.php template by default and add their output there via filters.

    Example in your settings you have /store/products/ as your slugs, then it creates a rewrite rule that maps /store/products/ to a pagename of 'product_list'. That way we can later detect that pagename, and hook all our content into it. Only the root store page is an actual page that you can apply a page template to the normal way.

    In this case you would probably just use mp_list_products(); instead of the loop.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.