How do I create a page template which takes PHP code in WordPress?

一曲冷凌霜 提交于 2019-12-12 06:15:39

问题


The following is the code I have used for creating a template for a particular page of my website. Since, it's a pre-conference and an independent event, I need to design this page slightly different from what I have used for the home page.

So, I have copied the page.php and tried to modify the template.

I want:

  1. I need to use the PHP code in the page in the WordPress page (because I need to do some query from my database and print it in the current page).

  2. The left sidebar should be the navigation menu (custom).

    Maybe this is the rough:

    <?php
        /**
         * Template Name:theme-meeting-template
         * This template will only display the content you entered in the page editor
         */
    ?>
    
    <?php
        /**
         * The template for displaying all pages.
         *
         * This is the template that displays all pages by default.
         * Please note that this is the WordPress construct of pages
         * and that other 'pages' on your WordPress site will use a
         * different template.
         *
         * @package panoramic
         */
    ?>
    
    <html <?php language_attributes(); ?>>
    
    <head>
        <meta charset="<?php bloginfo( 'charset' ); ?>">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="profile" href="http://gmpg.org/xfn/11">
        <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
    
        <?php wp_head(); ?>
    
        <div class="theme-head">
            <h1> The Fourth DAE-BRNS Theme Meeting on
                 Generation and use of Covariance
                 Matrices in the Applications of Nuclear Data</h1>
    
            <h2> December 09-13, 2017 </h2>
            <h2> Manipal University, Manipal, India </h2>
        </div>
    
        <div class="hor-nav" style="color: red; margin-top:20px; display: block">
            <ul>
                <li >
                    <a href="http://iclaa2017.com/test-template/">
                    home
                    </a>
                </li>
                <li >
                    <a href="#meetings">
                    Meetings </a>
                </li>
            </ul>
        </div>
    </head>
    
    <body <?php body_class(); ?>>
        <?php
            get_sidebar();
        ?>
    
        <div id="content" class="site-content site-container" >
    
            <?php if ( ! is_front_page() ) : ?>
    
                <?php if ( function_exists( 'bcn_display' ) ) : ?>
                <div class="breadcrumbs">
                    <?php bcn_display(); ?>
                </div>
                <?php endif; ?>
    
            <?php endif; ?>
    
            <div id="primary" class="content-area">
    
                <main id="main" class="site-main" role="main">
    
                    <?php get_template_part( 'library/template-parts/page-title' ); ?>
    
                    <?php while ( have_posts() ) : the_post(); ?>
    
                        <?php get_template_part( 'library/template-parts/content', 'page' ); ?>
    
                        <?php
                            // If comments are open or we have at least one comment, load up the comment template
                            if ( comments_open() || get_comments_number() ) :
                                comments_template();
                            endif;
                        ?>
    
                    <?php endwhile; // End of the loop. ?>
    
                </main><!-- #main -->
            </div><!-- #primary -->
    
        <?php get_footer(); ?>
    

Kindly click here for the output.

来源:https://stackoverflow.com/questions/42039833/how-do-i-create-a-page-template-which-takes-php-code-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!