ansonphong / postworld

Wordpress Theme Development Framework
GNU General Public License v2.0
7 stars 0 forks source link

load-post Directive - Use Template by Post Type #64

Closed ansonphong closed 10 years ago

ansonphong commented 10 years ago

Hi Michel, When I go to use load-post Directive to load up a post which has post_type : page, then it's showing it in the post template, not the page template.

Here is my embed code here:

    <script>
    var load_post = [];
    load_post['page'] = {
        post_id : {{ ID of the page here }},
        fields:   'all',
        view:     'full',
    };
    </script>
    <div load-post="page" ng-include="templateUrl"></div>

Now, when I look at the action=pw_get_templates AJAX command at runtime, I can see that the PHP function is correctly funding the page template which I have created in the over-rides folder.

Here is that part of the pw_get_templates object

posts : {
  page: {
    detail: "http://localhost:8888/wp-content/themes/RSV2/postworld/templates/posts/post-detail.html"
    full: "http://localhost:8888/wp-content/themes/RSV2/postworld/templates/posts/page-full.html"
    grid: "http://localhost:8888/wp-content/themes/RSV2/postworld/templates/posts/post-grid.html"
    list: "http://localhost:8888/wp-content/themes/RSV2/postworld/templates/posts/post-list.html"
  }
}

You will see that located at posts.page.full is the location of the page template URL: /theme/postworld/templates/posts/page-full.html

This is the template I would like it to use, although it's not loading the load-post Directive with the right templates given it's post type.

The template used should be from the appropriate post_type attributed to the given post.

michelhabib commented 10 years ago

confirmed, this is a bug related to post types that are not 'post', i will fix and confirm back here.

michelhabib commented 10 years ago

Actually, this could be another issue too, are you using load-post="<post_type>" to define the post_type ? so it's not just the id of the load_post array?

 <div load-post="<post_type>" ng-include="templateUrl"></div>

if that is correct, i would suggest you put the post_type inside the array, like this:-

<script>
    var load_post = [];
    load_post['identifier'] = {
        post_id : {{ ID of the page here }},
        fields:   'all',
        type: 'page',
        view:     'full',
    };
 </script>
 <div load-post="identifier" ng-include="templateUrl"></div>

Thoughts?

michelhabib commented 10 years ago

i added the suggested fix and change as in my last comment, it is simple to update it if you dont want it this way, just let me know what works best for you.

ansonphong commented 10 years ago

Yes, page is just the ID, not meant to define the post_type. It just happens to be the same.

How easy is it to pull the post_type from the actual postdata as it's coming via AJAX through the pwData service? Could we do some kind of $emit or $broadcast action for postType there if it's in a different scope?

That would be the ideal place to get the post_type data (from the pwData service), then we don't need to set it, since it's an extra step for the developer, and pw_get_templates is already loading all the template URLs by post type...

michelhabib commented 10 years ago

Re-reading your earlier comment it was obvious, i missed this one, it is now updated in latest commit and uses post.post_type to get the template.

The way this is implemented is as simple as setting the template after getting the response back in its success method [pwData.pw_get_post($scope.args).then()], and also to make sure that the templates object is retrieved, we call it in [pwData.templates.promise.then()] and we just set the $scope.templateUrl, which is going to reflect in ng-include directly.

ansonphong commented 10 years ago

Great.

ansonphong commented 10 years ago

Hi Michel, I have pulled the latest and I'm using the load-post directive on a page and it's still not changing the template. My usage is like this : Am I missing anything?

<script>
    var load_post = [];
    load_post['page'] = {
        post_id : <?php echo $post->ID; ?>,
        fields:   'all',
        view:     'full',
    };
    </script>
    <div load-post="page" ng-include="templateUrl"></div>

The post is loading fine, but it's still not using the correct template...

ansonphong commented 10 years ago

Hi Michel, I just also noticed that this is a wider issue which is also happening with the feeds as well. For instance, even though pw_get_templates is working as expected, when I use a load-feed, all the templates are using the "post" templates, not their respective post type templates.

michelhabib commented 10 years ago

i actually implemented it only in load-post today, i will need to check the rest and get back to you. But before i do that, let me address the first point, you are still getting the post template although you are using a page object? There are 2 things to consider, 1- you are sure it is a post of type "page"? [dumb question sorry] 2- you are sure you have page folder under your templates/posts either in your current theme or postworld plugin? [there are no folders for other post types in postworld as far as i can see, so it should be in your theme folder]. Note that if the folders do not exist, the template will fallback to post-{view_type}

Confirm please, then i will take it from here.

michelhabib commented 10 years ago

i guess i found an issue and tracing it now, hold on until i get back to you

ansonphong commented 10 years ago

Yes I am sure about both those questions, those are the first hings I checked. Also I can confirm that pw_get_templates is also aware of the correct over-ride template file and has it properly placed in the templates object.

Let me know what you find.

On Thu, Oct 31, 2013 at 5:49 PM, michelhabib notifications@github.comwrote:

i actually implemented it only in load-post today, i will need to check the rest and get back to you. But before i do that, let me address the first point, you are still getting the post template although you are using a page object? There are 2 things to consider, 1- you are sure it is a post of type "page"? [dumb question sorry] 2- you are sure you have page folder under your templates/posts either in your current theme or postworld plugin? [there are no folders for other post types in postworld as far as i can see, so it should be in your theme folder]. Note that if the folders do not exist, the template will fallback to post-{view_type}

Confirm please, then i will take it from here.

— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/64#issuecomment-27541016 .

michelhabib commented 10 years ago

yes, i missed something in my code you are absolutely right, check latest commit now for load-post and confirm. I will look at the rest now and report back. so i guess you want for feed directives to use - for each post - the correct post-type. that would apply to both load feed and live feed?

ansonphong commented 10 years ago

Correct, that certainly applies to both load feed and live feed yes - we always want to be showing a post in a template according to it's post type.

On Thu, Oct 31, 2013 at 6:33 PM, michelhabib notifications@github.comwrote:

yes, i missed something in my code you are absolutely right, check latest commit now for load-post and confirm. I will look at the rest now and report back. so i guess you want for feed directives to use - for each post - the correct post-type. that would apply to both load feed and live feed?

— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/64#issuecomment-27542357 .

ansonphong commented 10 years ago

Yes, confirmed it's working correctly now on load-post directive.

michelhabib commented 10 years ago

after latest commit, now the different post types will show different post templates, this applies to both live-feed and load-feed. i will need help in testing since i do not have much of these files.

ansonphong commented 10 years ago

ok I will test now.

ansonphong commented 10 years ago

at a first glance, it appears to be working correctly now.

On Thu, Oct 31, 2013 at 7:55 PM, michelhabib notifications@github.comwrote:

after latest commit, now the different post types will show different post templates, this applies to both live-feed and load-feed. i will need help in testing since i do not have much of these files.

— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/64#issuecomment-27544867 .