dongyi1015 2019-03-27 20:12
浏览 33

这个模板内置了什么样的代码?

I'm trying to create a custom page template, but the code in the page.php file in theme I'm using is not what I've experienced before.

TL;DR: Is there a name to this type of code/coding?

I usually am able to simply add in HTML in the body of the php file, but everything is looped (?) in here, and I'm not sure how to add any HTML in.

Because I don't know what to Google, I don't know how to figure this out or where to even start.

Here's the code from the page.php file:

<?php /* Template Name: Custom Template Name */


get_header();


list($masters_layout) = theme_page_layout_scheme();


echo '<!--_____ Start Content ____ -->' . "
";


if ($masters_layout == 'r_sidebar') {
    echo '<div class="content entry" >' . "
\t";
} elseif ($masters_layout == 'l_sidebar') {
    echo '<div class="content entry fr" >' . "
\t";
} else {
    echo '<div class="middle_content entry" >';
}


if (have_posts()) : the_post();
    $content_start = substr(get_post_field('post_content', get_the_ID()), 0, 15);


    if ($masters_layout == 'fullwidth' && $content_start === '[masters_row') {
        echo '</div>' . 
        '</div>';
    }


    the_content();

    echo '<div class="cl"></div>';


    if ($masters_layout == 'fullwidth' && $content_start === '[masters_row') {
        echo '<div class="content_wrap ' . $masters_layout . 
        ((is_singular('project')) ? ' project_page' : '') . 
        ((is_singular('profile')) ? ' profile_page' : '') . 
        '">' . "

" . 
            '<div class="middle_content entry" >';
    }


    wp_link_pages(array( 
        'before' => '<div class="subpage_nav" >' . '<strong>' . esc_html__('Pages', 'themename') . ':</strong>', 
        'after' => '</div>' . "
", 
        'link_before' => ' [ ', 
        'link_after' => ' ] ' 
    ));


    comments_template();
endif;


echo '</div>' . "
" . 
'<!-- _____ Finish Content _____ -->' . "

";


get_footer();

I'm used to seeing closed tags(?) and HTML thrown in there. For example:

<?php /* Template Name: Custom Template Name */ ?>
<?php get_header(); ?>

<!-- start content container -->
<div class="container">
<div class="row dmbs-content">

    <?php //left sidebar ?>

    <div class="main-content">

        <?php // theloop
        if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

            <h2 class="page-header"><?php the_title() ;?></h2>
            <?php the_content(); ?>
            <?php wp_link_pages(); ?>
            <?php comments_template(); ?>

        <?php endwhile; ?>
        <?php else: ?>

            <?php get_404_template(); ?>

        <?php endif; ?>

    </div>

    <?php //get the right sidebar ?>

</div>
</div>
<!-- end content container -->

<?php get_footer(); ?>

Any help is appreciated!

  • 写回答

1条回答 默认 最新

  • dq1230123 2019-03-27 20:29
    关注

    That is just PHP. A different style tho for sure... instead of opening and closing php around the HTML bits the template is just using the echo function to print out the HTML strings.

    <div class="cool-markup-bro">
      <?php some_function(); ?>
    </div>
    

    ...is the same as:

    <?php echo '<div class="cool-markup-bro">'; 
    some_function();
    echo '</div>'; ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么