【发布时间】:2019-08-18 12:30:52
【问题描述】:
我正在尝试创建一个自定义页面模板,但是我使用的主题中 page.php 文件中的代码不是我以前经历过的。
TL;DR:这种类型的代码/编码有名称吗?
我通常可以在 php 文件的正文中简单地添加 HTML,但是这里的所有内容都是循环的(?),我不知道如何添加任何 HTML。
因为我不知道 Google 会做什么,所以我不知道如何解决这个问题,甚至不知道从哪里开始。
这是 page.php 文件中的代码:
<?php /* Template Name: Custom Template Name */
get_header();
list($masters_layout) = theme_page_layout_scheme();
echo '<!--_____ Start Content ____ -->' . "\n";
if ($masters_layout == 'r_sidebar') {
echo '<div class="content entry" >' . "\n\t";
} elseif ($masters_layout == 'l_sidebar') {
echo '<div class="content entry fr" >' . "\n\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' : '') .
'">' . "\n\n" .
'<div class="middle_content entry" >';
}
wp_link_pages(array(
'before' => '<div class="subpage_nav" >' . '<strong>' . esc_html__('Pages', 'themename') . ':</strong>',
'after' => '</div>' . "\n",
'link_before' => ' [ ',
'link_after' => ' ] '
));
comments_template();
endif;
echo '</div>' . "\n" .
'<!-- _____ Finish Content _____ -->' . "\n\n";
get_footer();
我习惯于看到封闭的标签(?)和 HTML 被扔在那里。例如:
<?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(); ?>
感谢任何帮助!
【问题讨论】:
-
您所拥有的是所谓的“PHP 开发人员噩梦”,您正在查看以编程方式生成的内容。如果您需要对发生的事情进行深入描述,我可以给您,但我认为这里没有人会帮助您解决这个问题。
-
@CodiMech25 真是一场噩梦。嗯,我在“完成内容”之前关闭了 php 标签,然后重新启动它,我能够在它之间放置 HTML。希望这足以满足我的需要...感谢您与我们联系!
标签: php html wordpress wordpress-theming custom-wordpress-pages