Create a new page in WordPress theme

I am creating a functionality in WordPress where I need to create a new php page and have to link it in the menu section of my website. Though I can create a page from the dashboard but due to some reasons that option has been discarded.

Aim is to create a new page and link it with my existing site. I have created a page with following entries

Read More
<?php get_header(); ?>

    <div id="content">
        <span class="breadcrumbs"><a href="<?php echo get_option('home'); ?>/">Home</a> &raquo; Custom</span>
    <h2 class="title">Custom page</h2>
    <p align="center">
        <?php mycustomFucntion(); ?>
    </p>
    </div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

I am clueless how I can link it with my existing site so that when some one click on the link on menu user should be redirected to this page.

<ul id="page-bar" class="left clearfloat">

    <li><a href="<?php echo get_option('home'); ?>/">Home</a></li>

    <?php wp_list_pages('sort_column=menu_order&title_li='); ?>
    <li><a href="<?php echo get_option('home'); ?>/">CustomPage</a></li>
    </ul>

I am just playing around with php and WordPress in J2ee I know I can hit an action class and can return this custom page as new view but not sure how i can do this in WordPress.

Related posts

Leave a Reply

1 comment

  1. I think I understand what you want. You want to add a page to the current theme and for it to appear in the menu.

    If your page template has a different layout or function than existing ones you can add a custom page template like so:

    <?php //This part is required for WordPress to recognize it as a page template
    /*
    Template Name: Custom Template
    */
    ?>
    
    <?php get_header(); ?>
    
        <div id="content">
            <span class="breadcrumbs"><a href="<?php echo get_option('home'); ?>/">Home</a> &raquo; Custom</span>
        <h2 class="title">Custom page</h2>
        <p align="center">
            <?php mycustomFucntion(); ?>
        </p>
        </div>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    

    NOTE:
    You need to save the file, give it a name like my_custom_page.php and upload it to the current themes root folder.

    The next step would be to actually add a page using the Pages>Add New link in the WordPress Admin Screen. You should see the custom page template in the Add New Page Screen. It will be on the right side towards the bottom with a drop-down list entitled Page Attributes. Select the new page template and publish the page.

    As for the menu addition, it depends on what your theme is using for the navigation. If it uses the wp_nav function, just go to Appearance>Menus, in the pages section of that page find the page you added and select the check-box next to the title and click add menu item. Make sure to click the save menu button when you’re finished.

    If your theme is using wp_list_pages, the new page should be added automatically.