Display content of page template (get_page)

You seem to be confusing the database object that is a post/page, and the rendered output that is a post/page. The data contained in the wp_posts and wp_post_meta tables define the post object. A template file defines the rendered output when a given database object is queried.

There are three types of queries: the default, main query for a given context, secondary queries defined by core (such as the Nav Menu), and custom queries, that are defined elsewhere (either by the Theme or by a Plugin).

The default, main query for a given context is never affected by custom queries, even though it can be modified, either by filtering pre_get_posts or by bludgeoning it with query_posts().

What happens when you call get_page() is that WordPress queries the post object associated with a given ID, not the template file that would be used to render that object in its normal context.

Long story, short: if you want to run in some other context the same custom queries in each of your three custom page templates, you’ll need to execute the same code as you use on those three custom page templates.

(Also: please say you’ve not modified your Theme’s index.php file for this purpose? By doing so, you’ll completely break the template hierarchy for your Theme.)

The cleanest solution would be to split out the custom query code into template-part files, one for each custom page template; perhaps:

  • loop-three-latest-category-x.php
  • loop-three-latest-category-y.php
  • loop-three-latest-category-z.php

So, one of your custom page templates will look like so:

/**
 * Template Name: another page template
 * 
 * Category X custom page template
 * 
 * Used to display the three latest posts in 
 * category x.
 */

get_header();

get_template_part( 'loop-three-latest-category-x' );

get_footer();

Then, to output all three custom queries on the site front page, create a template file called front-page.php, and call all three template-part files from above:

<?php
/**
 * Front-page template
 * 
 * Used to render the site front page
 */

get_header();

get_template_part( 'loop-three-latest-category-x' );
get_template_part( 'loop-three-latest-category-y' );
get_template_part( 'loop-three-latest-category-z' );

get_footer();

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)