• xprojectsx

    (@xprojectsx)


    I’m trying to wrap my head around an idea would like some feedback on how to accomplish it.
    I have a custom post type and it displays fine. What I would like to do is for each of these posts, have a link on the individual post that displays an alternate view of that specific post. So the same post but using a different style sheet. For example, the post displays some text and an image and then I have a button on the post that says, “Show Alternate View” and clicking that button shows the same post but with a different style sheet.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Joy

    (@joyously)

    Are you wanting to keep the HTML the same and change the CSS?
    If so, is it all the CSS, or just add a class to the post that would then match the alternate CSS? This can be done with a small script that toggles the class, and the CSS would be in the same stylesheet that is already loaded.
    If you want to change the HTML or load a different stylesheet, you might need another request to the server. This could be a parameter on the URL that a plugin checks for, or a script that makes an AJAX call to load the other version.

    Thread Starter xprojectsx

    (@xprojectsx)

    I definitely want to load a separate style sheet. The html can be the same or different as long as it is displaying the same key elements such as post title, body text, image. I want to load a new version of the page and not javascript or ajax design elements on the same page.

    Joy

    (@joyously)

    It sounds like you can do it all in PHP. I suggest making a plugin.
    1. Write a function that runs before the theme loads, to detect the extra parameter on the URL.
    2. Inject the link to the other version by filtering ‘the_content’, using the info from step 1.
    3. Write a function to either filter the enqueued stylesheets or dequeue the original and enqueue the alternate, using high priority so it runs last. This can be generic if it’s the standard style.css or you might have to hardcode it if it’s some other stylesheet.

    Thread Starter xprojectsx

    (@xprojectsx)

    Thank you @joyously I’m going to try out this method and I’ll let you know how it goes. BTW didn’t wp previously have a built in method for creating alternate views?

    Joy

    (@joyously)

    There might be plugins that do pretty much what I suggested, but I doubt that WP ever had anything because it’s front end and that’s not WP’s job.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘alternate view of a post or custom post type’ is closed to new replies.