uncatcrea / wp-appkit

WP-AppKit WordPress plugin (create mobile apps connected to WordPress)
http://uncategorized-creations.com/
194 stars 65 forks source link

Custom page and sub pages #342

Closed Ices-Eyes closed 7 years ago

Ices-Eyes commented 7 years ago

Hi. In my app I have a custom about page, that should link inside some different pages from the wordpress blog. I'm unable to achive this tasks. The only thing I can manage is to make the links and open them with the single template, but not with the page one. I try to explain what I've done. In the WP control panel I add a new component with slug=about-page and type=post list (tryed also with WordPress Page, but the result is even worst) In a php file I defined this:

<?php
function wpak_get_about_page_links( $query_args, $component ) {
    if( $component->slug === 'about-page' ) {
        $query_args['post_type'] = 'page';
        $query_args['post__in'] = array( 111941, 29896, 44109 );
        $query_args[ 'orderby' ] = 'post__in';
    }

    return $query_args;
}
add_filter( 'wpak_posts_list_query_args', 'wpak_get_about_page_links', 10, 2 );
?>

On the functions.js in the app I defined this

App.filter( 'template', function( template, current_screen ) {
    if ( current_screen.component_id === 'about-page' ) {
        template = 'about-page';
    }
    return template;
} );

And defined an about-page.html file that among other things in the end has this:

<% if(posts.length) { %>
    <% _.each( posts, function( post, index ) { %>
        <span><a href="<%= TemplateTags.getPageLink( post.id ) %>"><%= post.title %></a></span><% index < (posts.length - 1)  ? print("&nbsp;&minus;&nbsp;") : print("") %>
    <% }); %>
<% } %>

Now, if I use the TemplateTags.getPageLink the links are in the form of #page/about-page/29896 but when clicked just send me the main screen of the app. If I use TemplateTags.getPostLink( post.id ) the links are in the form of #single/posts/29896 and once clicked bring me to a single page, that has wrong formatting for pages.

What I would like to obtain is to open those links with the page template and with the back button on top left corner, to go back to the about-page, and not with the menu button like they were first level pages.

Is this achievable? I'm doing something wrong or am I in a complete wrong way?

Thanks, Luca

mleroi commented 7 years ago

Hi Luca, I think using TemplateTags.getPostLink( post.id ) in your about-page.html template and adding the following condition:

if ( current_screen.screen_type === 'single' && current_screen.data.post.post_type === 'page'  ) {
        template = 'page';
}

in your App.filter( 'template' ) filter should work ?

Ices-Eyes commented 7 years ago

Thanks! It work perfectly :)

mleroi commented 7 years ago

Great! Thanks for the very clear and well detailed question, have fun building your app :)