• Resolved stflag

    (@stflag)


    I have an issue my team can’t deal with and I want to know if there is a solution for the problem or if this is a lost cause.

    Here is the situation.

    I have a WP article which is in two Worpress Categories:
    – Cat 1
    – Cat 2

    I want this article to have two different page layout whether I view this article in Cat 1 or in Cat 2

    The difference in the layout is for a elements in the right column.

    When I’m Cat 1, I want the article to display with certain elements in the right column.
    When I’m Cat 2, I want the same article to display other elements in the right column.

    In other words, depending in what category I am, I want the article to display different information in the right column.

    My programmers tell me that this is not possible because of the nature of the permalink of the article that links it to a specific category and layout.

    Is this true?
    If so, is there a workaround, like have a condition in the right column based on navigation path for example.
    If not, how do you do that?

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Idea: Create a different category template for the second category.

    Copy your category.php. Edit to create your unique display. Save it as category-id.php where id equalls the particular categories id that you want a different display for.

    Read: http://codex.wordpress.org/Category_Templates

    Thread Starter stflag

    (@stflag)

    Thanks FlashBuddy.

    We have multiple templates for our categories, our issue is calling the article to display in that template.

    The context is that we’re launching a WordPress news website. A news article must be displayed in its news category (Business for example) with a certain layout but then we also want to display the same article in a weekly Case Study which has a different layout.

    In other words we want the article layout to be different whether we are in Business or in the Case Study page.

    How do you manage the URL of the article in this case?

    Thanks.

    I’m assuming the issue is with the single (full) view of the article?

    You can handle this with conditionals in single.php:

    if ( in_category( 'casestudy' )) {
    	// Case Study layout
    } else {
    	// regular layout
    }

    It won’t matter what your permalinks are in this case.

    http://codex.wordpress.org/Function_Reference/in_category

    Thread Starter stflag

    (@stflag)

    Here are two solutions that were suggested to me:

    1. Keep track of the latest category visited in a $_SESSION variable and thus you would know how to style the single article.
    By: Jacob Guite St-Pierre (Montreal, QC, Canada) http://twitter.com/JacobGSP

    2. In categories Templates, customize the permalink by adding a query variable such as &skin=cat_id at the end of the permalink.
    Then in single.php, check the presence of the query variable ‘skin’. In the case where it is there, wp_enqueue_style a CSS file that would manage the wanted look and/or include another single_skin_CAT_ID.php with the markup and the appropriate template tags.
    By: Alexandre Simard (Montreal, QC, Canada) http://twitter.com/qbert72

    Solution #2 worked better for us and solved the problem.

    Thanks again to the Montreal WordPress Community to have helped me out with this very tricky issue!

    Cheers,
    Stf

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Same article, two different layouts depending on category’ is closed to new replies.