Avatar andyjames asked

How to apply a complex page template in wordpress Warp?

This question is related to my other question about the hierarchy but is a little more specific.

http://yootheme.com/support/question/5323

What would be the best way to add a page template to Warp I previously developed for displaying a portfolio. The user creates a page in WP and then selects the portfolio template and there is a whole bunch of wp meta options under the page contents to set the functionality of the portfolio which can filter content, has masonary and auto scroll as well.

Currently its all inside a file called page-portfolio.php and set as a page template.

I don't see how I would achieve this with Warp profiles? Or how would I do this?

Thanks,

Andy

  • WordPress
  • Warp Theme
  • General Question

Edited

11 Answers

0

Avatar chris.kyriacou answered

I need to understand how to do this for a custom post...

0

Avatar nicholas.osinski answered

Again, this is a great solution - Thank you!

One PROBLEM though... the solution does not seem to carry through on the MOBILE version of the template - what's the missing step so that the new templated page also appears on the MOBILE version of the site?

Thanks again!

0

Avatar nkoning answered

Had some troubles getting it to work with the new Tasty template, but it works now!

Thanks for this very nice and helpfull explanation, it's really helpfull and excactly what i need.

0

Avatar art.webb answered

Wow this is exactly what I was looking for. What I'd like to do is have a page with a news category stream below the page content. Has anyone created that code before using this method? I'm so eager for this information!

Coming from Joomla, this template code is the missing piece of the puzzle for YooTheme + Wordpress -- pages with news category streams below the page content.

0

Avatar andyjames answered

I do not have a working example at the moment, just the test install I tested this on.

0

Avatar hans.swolfs answered

Hey Andy,

looking great! Thanks for the walkthrough!
Do you have this in action somewhere to see?

0

Avatar elsue answered

It works for a custom post type and with a custom style which is nice. Thanks for the walk through, it saved me a lot of headaches.

22

Avatar andyjames answered

Got it working! :)

Traditional way in WP

Create a file called page-example.php and make sure you add the header at the top and custom code

<?php  
/*  
Template Name: Example Page Template  
*/  
?>

<?php  
get_header()  
// add custom layout and loop code  
get_footer()

Then you create a new page in the WP admin and set the page template on the Page Edit Screen to "example page template". Now whatever code is in the page template will load when that page is loaded based on the hierarchy.

Getting the same result in Warp

1) Create a file called page-example.php and make sure you add the header at the top. This is important so it can be selected on the Page Edit Screen's page attributes.

<?php  
/*  
Template Name: Example Page Template  
*/  
?>

Here is where it is different.. instead of adding the code as you would in WP you tell it to get the layout with the same name

<?php 

// get warp    
$warp = Warp::getInstance();    

// load main template file    
echo $warp['template']->render('template');

Note the render('template'); bit that's the important part! It tells warp to load the main template.php and add whatever is in layouts/page-example.php (step 2) where $content is called. Once we have done step 2 and 3 this will work.

2) Now create another page-example.php and put it inside the main templates /layouts/ folder so you now have 2 files with the same name, one in the template root and one in the layouts.

Image

Inside this file you add the code you want to output on the page. This is essentially the loop and whatever wraps around it. Since this will be output into the template.php where we call the render('content') section.

<div id="system">  
    <h3>My Custom Page</h3>  
    <?php if (have_posts()) : ?>  
        <?php while (have_posts()) : the_post(); ?>  

        <article class="item">  

            <header>  

                <h1 class="title"><?php the_title(); ?></h1>  

            </header>  

            <div class="content clearfix"><?php the_content(''); ?></div>  

            <?php edit_post_link(__('Edit this post.', 'warp'), '<p class="edit">','</p>'); ?>  

        </article>  

        <?php endwhile; ?>  
    <?php endif; ?>  

    <?php comments_template(); ?>  

</div>

3) Copy warp/systems/wordpress/layouts/content.php to the main templates layouts/ folder so we can override it.

Now in the new file we modify the is_page() part to check for our page template as well

elseif (is_page()) {  
    $content = 'page';

Becomes

} elseif (is_page()) {  
    if (is_page_template('page-example.php')) {  
        $content = 'page-example';  
    } else {  
        $content = 'page';  
    }

So instead of this

if (is_home()) {  
    $content = 'index';  
} elseif (is_page()) {  
    $content = 'page';  
} elseif (is_attachment()) {  
    $content = 'attachment';  
} elseif (is_single()) {  
    $content = 'single';  
} elseif (is_category()) {  
    $content = 'category';  
} elseif (is_search()) {  
    $content = 'search';  
} elseif (is_archive() && is_author()) {  
    $content = 'author';  
} elseif (is_archive()) {  
    $content = 'archive';  
} elseif (is_404()) {  
    $content = '404';  
}

You will have this

if (is_home()) {  
    $content = 'index';  
} elseif (is_page()) {  
    if (is_page_template('page-example.php')) {  
        $content = 'page-example';  
    } else {  
        $content = 'page';  
    }  
} elseif (is_attachment()) {  
    $content = 'attachment';  
} elseif (is_single()) {  
    $content = 'single';  
} elseif (is_category()) {  
    $content = 'category';  
} elseif (is_search()) {  
    $content = 'search';  
} elseif (is_archive() && is_author()) {  
    $content = 'author';  
} elseif (is_archive()) {  
    $content = 'archive';  
} elseif (is_404()) {  
    $content = '404';  
} 

That works perfectly!! Now when I load the page that is assigned to this page template, whatever is in my layouts/page-example.php (loop part) will be output inside the layouts/template.php wherever the render content is called.

<?php echo $this['template']->render('content'); ?> 

This in theory will work for pretty much anything in the hierarchy. While it is not perfect, it is a workable solution.

If someone else can test this out, that would be great.

Andy

Edited

0

Avatar david.carroll answered

Andy,

Ah... really good question. Is Portfolio registered as a Custom Post Type or is this simply a page template that is selected on the Page Edit Screen? I don't think the latter will be possible without the awesome solution you presented.

UPDATE: I added the italicized text above as a correction to my original post after Andy posted his detailed solution.

However, if portfolio is registered as a Custom Post Type called Portfolio, and you create a new Portfolio item, then I believe you can create a a copy of page.php into a new file named page-portfolio.php. This is based on what I understand in the Create a new style documentation. I have not tested this myself.

If this works as documented, then you can register the meta boxes for this Custom Post Type.

If you wouldn't mind doing a quick test and reporting your findings, that would be AWESOME!!! Otherwise, I can try to test sometime tomorrow.

Best Regards,

David Carroll

Edited

0

Avatar david.carroll answered

YEA!!! Another developer who can present code in documentation like style!!!

You are my new best friend in this community :D

Seriously... Brilliant review. I had not considered this for setting up page layouts. I'm excited like you can't imagine.

I'll try to confirm this... but, I'm slammed doing some development.

I've clicked the +1 for your response.

0

Avatar andyjames answered

Hey David,

Is Portfolio registered as a Custom Post Type or is this simply a page template that is selected on the Page Edit Screen?

It is both. Portfolio is a Custom Post Type and the Page template is applied from the Page Edit Screen

Thanks for the suggestion and I think you are onto something but since I want this to work in the master template and not only a style (child theme) then I would add the file in the main templates /layouts/ folder. Also, my aim is to get it to work as close to how it does in wp.

I have an idea based on what Artur suggested in my other question for the category.php in conjunction with the changes to the content.php I added using an override in the /layouts/ folder. This may just work and will also mean there is a way to overcome the limitations I expressed in my other question. It wont be completely straight forward, but it does mean its possible with just and extra 1 or 2 steps.

Will post my findings once I have tested it :)

Edited

Know someone who can answer? Share a link to this question via email or twitter.