Either way you generally use the_content(), the setup in each case is different though. I don’t quite understand what you’re trying to do. A page template is a sort of single post template that is specific for pages. Why do you want another single template? A single template is a full page template — header, body, sidebar, footer. Do you want all this within your page template that is also outputting header, body, sidebar, footer as well?
I would think you want a template part, not a full page. Many themes compose their templates of these parts that are common to several full page templates. Thus code can be updated on one file instead of updating the same thing on several files. You load template parts with get_template_part(). Such templates need to be in the theme’s folder somewhere.
You can also load template parts like you would load any PHP code file from another, with require
or include
statements. get_template_part() essentially does the same thing, but it has special functionality to find the right file in the theme and ensuring the proper text domain is loaded for it.
(this page is only for Mobile App) .
The idea is that this is done entirely within the specified template so that the site is not affected by this customization
I hope you understand what is required
how can i do it ?
thanks
While you do not need to load the header, you do need to call wp_head() or external resources will not be loaded. Also call wp_footer() at the very end. Despite the names, these generally do not generate visible output, they merely do certain actions that are required to load scripts and stylesheets. You do need the minimal HTML from your header template — !DOCTYPE, html, head, charset, viewport, and body elements. Plus any major containers used by your theme.
Make a new WP_Query object that gets the desired posts and then run a Loop to display the posts in whatever manner you wish. No need to include or load other templates. Put it all on your one page template that stands on its own.
A completely different approach would be to get the posts data you want using the REST API. It will come as JSON data. It would be up to your app to parse the data and compose the output. Maybe you don’t want to consider this right now, but I urge you to look into this sometime soon if you intend to continue developing mobile apps.
]]>this is the template file
<?php
/*
Template Name: Mobile App Template
*/
?>
<?php get_header('mobapp'); ?>
<div class="content">
<?php if( get_query_var('page') ) $paged = get_query_var('page') ; ?>
<div class="page-head">
<h1 class="page-title">
<?php the_title(); ?>
</h1>
</div>
<?php
$blog_cats = unserialize($get_meta["blog_cats"][0]);
if( empty( $blog_cats ) ) $blog_cats = get_all_category_ids();
query_posts( array( 'paged' => $paged , 'category__in' => $blog_cats ));
get_template_part( 'loop', 'category' );
if ($wp_query->max_num_pages > 1) pagenavi();
?>
<?php comments_template( '', true ); ?>
</div><!-- .content -->
<?php get_footer('mobapp'); ?>
well it display list of posts with Specific header and footer
Please keep in mind that the page of this template works without a problem , but when you go to the page displaying the Selected news like(/?p=123) it appears containing the default header and footer of theme.
Well, even though it’s not what you want, that is normal, expected behavior for WP, but that can be changed. Do you have a similar template for non-mobile devices? Is the header/footer the only difference? How do mobile users come to be using this template? Are you using wp_is_mobile()? You could use wp_is_mobile() to serve one header/footer or the other, all on a single template. This alone still would not help the single post ID 123, but you could also use the same wp_is_mobile() logic on single.php and any other templates to load the mobile content when appropriate.
A completely different approach would be to load the clicked post via Ajax on the same template/page, either replacing the initial list or overlaying it using a modal. The way the single post is displayed would depend on what your Ajax client script and server handler do together. It’s conceivable a template could be part of this, but you are better off developing your own code. Use the same containers and classes, etc. that your theme does so the appearance is consistent. With Ajax, you would need to capture back button events to deliver the expected results because the device thinks the user is still on the your initial page and an uncaptured back button would load whatever was up before your page instead of going back to the initial list.
It’s not so important that it must be addressed right away, but you shouldn’t be using query_posts() these days. There’s more efficient ways to do queries. Either instantiate a new WP_Query object (or use get_posts()) or use the “pre_get_posts” action to alter the original request’s query vars to meet your needs.
]]>