• I have a page layout which I am using for a custom post type.
    lets say each page is at mysite.com/customtype/mypost

    I would like to have a second layout for this page to basically show a slightly altered / more concise version (using the same post info) which could be accessed at something like mysite.com/customtype/mypost/alt or mysite.com/customtype/mypost?alt or similar.

    What might be the best way of going about this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’d go about it with a query string and CSS.

    Add a query string to your links, so something like mysite.com/customtype/mypost?myview=concise

    Then at the top of your single-customtype.php, have $myview = $_GET['myview'];

    Add this to your body classes in header.php (how you do this depends on your theme, but for me it’d be <body <?php body_class( $myview ); ?>>).

    Finally you can easily control what is and isn’t seen using CSS, eg body.concise .myclass { display: none; }

    Hope that helps

    Thread Starter mortonc

    (@mortonc)

    Thank you Peter that is very helpful.

    But if I wanted to have a completely different layout all together how would I go about doing that?

    That’s the beauty of CSS… the same HTML can be displayed in different ways.

    For example, a box can be floated right for normal view, or floated left for another, eg:

    .myclass { float: right; }
    body.concise .myclass { float: left; }

    Doing it that way would keep your development to a minimum as you’d only need one set of code.

    But, if you wanted to, the query string can still be used, eg:

    $myview = $_GET['myview'];
    if ( $myview != "concise" ) {
    	// code to display normal view
    } else {
    	// code to display concise view
    }

    Oh, BTW, when I said originally “at the top of your single-customtype.php” I meant “at the top of header.php“!

    Peter

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multiple layout for posts’ is closed to new replies.