使用HTML将三个PHP if查询添加到一个页面中
我有三个使用HTML将三个PHP if查询添加到一个页面中,php,arrays,wordpress,loops,if-statement,Php,Arrays,Wordpress,Loops,If Statement,我有三个 <?php if( array_key_exists( 'overview', $wp_query->query_vars ) ){ ;}?> 我需要他们包含以下的变化 <div class="content "> <div class="container-fluid bg-transparent m-t-50 container-fixed-lg"> <div class="row">
<?php if( array_key_exists( 'overview', $wp_query->query_vars ) ){
;}?>
我需要他们包含以下的变化
<div class="content ">
<div class="container-fluid bg-transparent m-t-50 container-fixed-lg">
<div class="row">
<div class="col-md-6">
<button onclick="location.href='/campaigns'" class="btn btn-default btn-xs btn-rounded m-r-20"><i class="fa fa-angle-left" style="color:#828ba4"></i> <span class="back-campaign">Back to campaigns</span></button>
<h1>
<?php the_title(); ?>
</h1>
</div>
<div class="col-md-6 hidden-md-up">
<div class="pull-left">
<a href="<?php echo esc_url( get_permalink() ); ?>/analytics">
<button class="m-t-10 m-b-10 btn btn-grey btn-cons" type="button">
View Analytics
</button>
</a>
<a href="<?php echo esc_url( get_permalink() ); ?>/edit-campaign">
<button class="m-t-10 m-b-10 btn btn-primary btn-cons" type="button">
Edit Campaign
</button>
</a>
</div>
</div>
</div>
</div>
回到竞选活动
我相信我正在寻找的解决方案是做一些类似于下面的事情,因为我不希望它们成为回音
<?php if( array_key_exists( 'overview', $wp_query->query_vars ) );?>
<div>HTML Content for overview</div>
<?php endif; ?>
<?php if( array_key_exists( 'analytics', $wp_query->query_vars ) );?>
<div>HTML Content for analytics</div>
<?php endif; ?>
<?php if( array_key_exists( 'analytics', $wp_query->query_vars ) );?>
<div>HTML Content for analytics</div>
<?php endif; ?>
用于概述的HTML内容
用于分析的HTML内容
用于分析的HTML内容
当尝试这种方法时,我收到一个500的错误,但这是沿着我试图实现的路线
谢谢您的时间。解决方案是使用HTML内容创建一个单独的文件,另存为
.php
。然后,使用include(“file_name.php”)代码>内
<?php if( array_key_exists( 'overview', $wp_query->query_vars ) ){;}?>
假扮
<?php if( array_key_exists( 'overview', $wp_query->query_vars ) ){
include("single-campaign-overview.php");}?>
我确实注意到页面加载时间有点延迟,但这还不足以成为问题。使用
而不是
您可以使用打印
(与echo
)或incude
@RJParikh谢谢您的帮助。这将允许我复制HTML而不格式化它的PHP?应该避免。短标记可以在任何服务器配置中关闭。我知道更好的方法是将HTML完全转换为PHP,而不是使用单独的文件。然而,我正在寻找一种最省时的方法来完成这项工作。如果有人有更好的解决方案,请分享。
<?php if( array_key_exists( 'overview', $wp_query->query_vars ) ){
include("single-campaign-overview.php");}?>