Calling the Custom post type on my template pages
-
Hello Everyone
My question is related to the Custom Post Type Calling on the Template.
1.I have Registered a new post type on my function file and added some posts to that.
2.I want to call that custom posts with there title and content on a template page.
Here is My Codefunction register_mytestpage_post_types() {
$labels=array(
‘name’ => ‘MyTestPages’,
‘singular_name’ => _x( ‘MyTestPage’, ‘post type singular name’, ‘your-plugin-textdomain’ ),
‘menu_name’ => _x( ‘MyTestPage’, ‘admin menu’, ‘your-plugin-textdomain’ ),
‘name_admin_bar’ => _x( ‘MyTestPage’, ‘add new on admin bar’, ‘your-plugin-textdomain’ ),
‘add_new’ => _x( ‘Add New’, ‘book’, ‘your-plugin-textdomain’ ),
‘add_new_item’ => __( ‘Add New MyTestPage’, ‘your-plugin-textdomain’ ),
‘new_item’ => __( ‘New MyTestPage’, ‘your-plugin-textdomain’ ),
‘edit_item’ => __( ‘Edit MyTestPage’, ‘your-plugin-textdomain’ ),
‘view_item’ => __( ‘View MyTestPage’, ‘your-plugin-textdomain’ ),
‘all_items’ => __( ‘All MyTestPage’, ‘your-plugin-textdomain’ ),
‘search_items’ => __( ‘Search MyTestPage’, ‘your-plugin-textdomain’ ),
‘parent_item_colon’ => __( ‘Parent MyTestPage:’, ‘your-plugin-textdomain’ ),
‘not_found’ => __( ‘No books found.’, ‘your-plugin-textdomain’ ),
‘not_found_in_trash’ => __( ‘No books found in Trash.’, ‘your-plugin-textdomain’ )
);
$arguments=array(
‘labels’=>$labels,
‘public’=>true
);
register_post_type( ‘Test_Page’,$arguments);
}
add_action(“init”,”register_mytestpage_post_types”);3.Now Calling it to my Template Page
/**********************************************************
<?php
$argument=array(
‘posts_per_page’=>’3’,
‘post_type’=>’Test_Page’
);
$posts=new WP_Query($argument);
?>
<?php while ( $posts->have_posts() ){ ?>
<?php $posts->the_post(); ?>
<div class=”col-md-4 animated growIn slow”>
<div class=”text-center balack_columns”>
<?php
if (is_page(“Team of bio medical scientist”)) { ?>
<div class=”icon_round i_heart”></div>
<?php } elseif (is_page(“Robust App Development”)) { ?>
<div class=”icon_round i_mobile”> </div>
<?php } elseif (is_page(“Health, Fitness & Productivity”)) { ?>
<div class=”icon_round i_run”> </div>
<?php } else { echo ‘hello nothing found’; ?>
<?php } ?>
<h3 class=”header_red text-uppercase”><?php the_title(); ?></h3>
<p><?php the_content(); ?></p>
</div>
</div><?php } ?>
<?php wp_reset_query(); ?>//******************************************************************
Problem Description:
If-else loop inside the while loop is reading only the last else part(echo part)
I want to call the different div’s on each page title.
Is There is Any Problem On Calling the Loop?Please suggest me what is the error
- The topic ‘Calling the Custom post type on my template pages’ is closed to new replies.