• Hope someone can help.

    Is there a way I can have (some) WP categories, link direct to a WP page, rather than a list of posts in that category (as would happen normally)?

    Let me explain my use-case / what I want to achieve…

    I have a number of products (actually, mobile games) on my site. Each game is assigned a category, e.g. “Asteroids”.

    There is a main product page for each game, as well as a number of related blog posts, such posts will be assigned a category, e.g. “Asteroids”.

    When a user clicks on a category link, I want them to go to the main product page; e.g. mysite.com/games/asteroids.

    I have achieved this in the past, though my solution is probably not too elegant, and I’m hoping there may be a better way to achieve the same result?

    What I did before, was basically create templates for each game, e.g. “category-asteroids.php”, which renders out all the game specific data, followed by posts in category.

    What do people think? Is there a better solution to achieve the same result? It’s just the getting categories to link to a page bit, that I’m struggling with.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Your method of using specific category template is the first I think of but of course it’s not the only way to achive this.

    I would manually create a regular Page for each category, this way we are free to put in any content into the page, and then make a link to the category archive.

    Instead of having category archive links in the menu, we’d just put in the link to those pages.

    Moderator bcworkz

    (@bcworkz)

    How you organize your posts and games and how you display them are really two different things. Organize by what ever makes sense to you. Display can be coded to fit your organizational scheme. Strive for the least amount of templates and pages required to accomplish what you want.

    Unless each category’s display is distinctly different, you ought to be able to have a single page/template to display all games. The content displayed is determined by query vars that are specified by elements in the permalink or by added query args appended to the permalink. So part of how this template or page is coded depends on how you want the permalinks to be structured. In some cases, WP can interpret certain structures without further coding. If not, additional rewrite rules can be specified so the query can be properly constructed.

    It sounds like your games are already a custom post type like “product”. It can be labeled anything you want, like “game”, but internally WP still wants to use the “product” designation. It may be that the categories for products are not the same taxonomy as categories for posts. It’s also possible it’s the same taxonomy, it depends on what e-commerce plugin you are using. Like for post types, the outward label may still be “category”, but the underlying taxonomy name used internally might be different. For example, “category” for posts and “product-cat” for products.

    From your description, I think you should simply alter the existing single product page to also list blog posts that fall into the same category. This can be done by adding code that instantiates a new WP_Query class, then loops through the results. If games and blog posts share the same taxonomy, getting the game’s taxonomy for use in querying for posts is fairly straight forward.

    If they are different taxonomies, you’d need to be sure there are matching terms in each or have an alternative way of relating game taxonomy terms to post categories. One way or the other, you can add related posts to a single product template. No need for separate templates or pages for each category.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conflating page with category?’ is closed to new replies.