我正在一个网站上工作。我是usng page.php来控制所有页面,即使它们有不同的类别。在我的本地服务器(XAMPP)上一切正常,我可以查看所有页面,但是当我在线上传时,在尝试查看页面时出现解析错误。我该如何构建这个page.php文件?
我不想创建的所有网页单个文件,所以我决定所有page.php文件使用if (is_page(page_id)
这是我得到了错误的地方:
解析错误:语法错误,第一行中/----/woodclef.com/wp-content/themes/woodclef/page.php出现意外的'endwhile'(T_ENDWHILE)
结帐通过网站:www.woodclef.com密码为12345678
已修改
我现在有一个更清洁的代码,错误消失了,但即使类别ID和页面ID为真,也没有显示任何帖子。任何人都可以帮助弄清楚什么可能是错的?
<?php
//Highlights
if (is_page(10)) {
$args = array(
'posts_per_page' => -1,
'cat' => 5
);
$sticky_query = new WP_Query($args);
$count = 0;
while ($sticky_query->have_posts()) : $sticky_query->the_post();
$count++;
if ($count == 1) :
get_template_part('pages/common_template_a');
elseif ($count == 2) :
get_template_part('pages/common_template_a');
else :
get_template_part('pages/common_template');
endif;
endwhile;
wp_reset_postdata();
}
//News
if (is_page(144)) {
$args = array(
'posts_per_page' => -1,
'cat' => 6
);
$sticky_query = new WP_Query($args);
$count = 0;
while ($sticky_query->have_posts()) : $sticky_query->the_post();
$count++;
if ($count == 1) :
get_template_part('pages/common_template_a');
elseif ($count == 2) :
get_template_part('pages/common_template_a');
else :
get_template_part('pages/common_template');
endif;
endwhile;
wp_reset_postdata();
}
?>
我重新使用php的famework像laravel。使用路由器 –
为什么你总是打开和关闭php标签?这是绝对没有必要的,只会导致错误。 –
@CharlotteDunois我该怎么办?你的意思是我应该删除顶部的开标签和下面的标签? – Sam