Wordpress-在短代码变量中包含PHP
我正在尝试创建一个短代码,以复制以下工作正常的代码:-Wordpress-在短代码变量中包含PHP,php,wordpress,Php,Wordpress,我正在尝试创建一个短代码,以复制以下工作正常的代码:- $currency = get_field('currency', 'options'); $args = array( 'posts_per_page'=> -1, 'post_type' => 'properties', ); $featured_query = new WP_Query( $args ); ?> <!-- Featured Properties --
$currency = get_field('currency', 'options');
$args = array(
'posts_per_page'=> -1,
'post_type' => 'properties',
);
$featured_query = new WP_Query( $args ); ?>
<!-- Featured Properties -->
<h1 class="text-grey"><span class="xstrong">Featured</span> Properties</h1>
<div id="featured-properties">
<div class="container">
<?php if( $featured_query->have_posts() ): $property_increment = 0; ?>
<div id="featured-carousel" class="carousel slide" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner row" role="listbox">
<?php while( $featured_query->have_posts() ) : $featured_query->the_post(); ?>
<?php if($property_increment==0 || $property_increment%3==0 ){ echo '<div class="item '.(($property_increment==0)?'active':'').'">'; } ?>
<div class="col-md-4 col-sm-6 col-xs-12 row">
<div class="property-wrapper">
<a href="<?php echo get_permalink(); ?>">
<div class="corner"></div><p class="corner-text"><?php the_field('house_status'); ?></p>
<?php the_post_thumbnail($featured_query->ID, ''); ?>
<div class="property-details">
<h5 class="property-title"><?php the_title(); ?>,</h5>
<h6 class="property-title"><?php the_field('house_town'); ?></h6>
<h6 class="property-type"><?php the_field('house_type'); ?></h6>
<?php $price = number_format(get_field('house_price')); ?>
<h5 class="property-price"><?php echo $currency . $price; ?></h5>
<h5 class="property-bedrooms"><?php the_field('house_bedrooms'); ?><span class="icon-bedrooms"></span></h5>
<h5 class="property-bathrooms"><?php the_field('house_bathrooms'); ?><span class="icon-bathrooms"></span></h5>
<span class="btn btn-white full">More Details</span>
</div>
</a>
</div>
</div>
<?php echo ($property_increment%3==2)?'</div>':''; ?>
<?php $property_increment++; endwhile; ?>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#featured-carousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#featured-carousel" role="button" data-slide="next">
<span class=" glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<?php endif; wp_reset_query(); ?>
</div>
</div><!-- / Featured Properties -->
$currency=get_字段('currency','options');
$args=数组(
“每页帖子数”=>-1,
“post_type”=>“properties”,
);
$featured_query=新的WP_查询($args);?>
特色物业
我的问题是,当我试图将其创建为一个快捷码时,你不能使用echo,如果,在变量中,我认为它现在就快存在了,我只是不知道我需要做些什么来让它工作,例如,当我在变量中使用它时,我该如何替换“while”和“endif”
以下是我到目前为止的情况:-
/**
* Shortcode: Latest Properties
*/
function latest_content_properties_func( $atts ) {
$currency = get_field('currency', 'options');
$args = array(
'posts_per_page'=> -1,
'post_type' => 'properties',
);
$featured_query = new WP_Query( $args );
$featured_content_properties = '';
$featured_content_properties = '<div id="featured-properties">';
$featured_content_properties .= '<div class="container">';
$featured_content_properties .= ( $featured_query->have_posts() ) . $property_increment = 0;
$featured_content_properties .= '<div id="featured-carousel" class="carousel slide" data-ride="carousel">';
$featured_content_properties .= '<div class="carousel-inner row" role="listbox">';
$featured_content_properties .= while( $featured_query->have_posts() ) : $featured_query->the_post();
$featured_content_properties .= ($property_increment==0 || $property_increment%3==0 ) . '<div class="item '.(($property_increment==0)?'active':'').'">';
$featured_content_properties .= '<div class="col-md-4 col-sm-6 col-xs-12 row">';
$featured_content_properties .= '<div class="property-wrapper">';
$featured_content_properties .= '<a href="'. get_permalink() .'">';
$featured_content_properties .= '<div class="corner"></div><p class="corner-text">'. get_field('house_status') .'</p>';
$featured_content_properties .= get_the_post_thumbnail($featured_query->ID, "");
$featured_content_properties .= '<div class="property-details">';
$featured_content_properties .= '<h5 class="property-title">'. get_the_title() .',</h5>';
$featured_content_properties .= '<h6 class="property-title">'. get_field('house_town') .'</h6>';
$featured_content_properties .= '<h6 class="property-type">'. get_field('house_type') .'</h6>';
$featured_content_properties .= $price = number_format(get_field("house_price"));
$featured_content_properties .= '<h5 class="property-price">'. $currency . $price .'</h5>';
$featured_content_properties .= '<h5 class="property-bedrooms">'. get_field('house_bedrooms') .'<span class="icon-bedrooms"></span></h5>';
$featured_content_properties .= '<h5 class="property-bathrooms">'. get_field('house_bathrooms') .'<span class="icon-bathrooms"></span></h5>';
$featured_content_properties .= '<span class="btn btn-white full">More Details</span>';
$featured_content_properties .= '</div>';
$featured_content_properties .= '</a>';
$featured_content_properties .= '</div>';
$featured_content_properties .= '</div>';
$featured_content_properties .= ($property_increment%3==2)? '</div>':'';
$featured_content_properties .= $property_increment++; endwhile;
$featured_content_properties .= '</div>';
$featured_content_properties .= '<a class="left carousel-control" href="#featured-carousel" role="button" data-slide="prev">';
$featured_content_properties .= '<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>';
$featured_content_properties .= '<span class="sr-only">Previous</span>';
$featured_content_properties .= '</a>';
$featured_content_properties .= '<a class="right carousel-control" href="#featured-carousel" role="button" data-slide="next">';
$featured_content_properties .= '<span class=" glyphicon-chevron-right" aria-hidden="true"></span>';
$featured_content_properties .= '<span class="sr-only">Next</span>';
$featured_content_properties .= '</a>';
$featured_content_properties .= '</div>';
$featured_content_properties .= endif; wp_reset_query();
$featured_content_properties .= '</div>';
$featured_content_properties .= '</div>';
return $featured_content_properties;
}
add_shortcode( 'latest_content_properties', 'latest_content_properties_func' );
/**
*快捷码:最新属性
*/
函数最新内容属性函数($atts){
$currency=get_字段('currency','options');
$args=数组(
“每页帖子数”=>-1,
“post_type”=>“properties”,
);
$featured\u query=新的WP\u查询($args);
$featured_content_properties='';
$featured_content_properties='';
$featured_content_properties.='';
$featured\u content\u properties.=($featured\u query->have\u posts())。$property\u increment=0;
$featured_content_properties.='';
$featured_content_properties.='';
$featured_content_properties.=while($featured_query->have_posts()):$featured_query->the_post();
$property_content_properties.=($property_increment==0 | |$property_increment%3==0)。“”;
$featured_content_properties.='';
$featured_content_properties.='';
$featured_content_properties.='';
$featured_content_properties.='';
$featured_content_properties.='';
$properties\u content\u properties.=($property\u增量%3==2)?“”:“”;
$featured_content_properties.=$property_increment++;endwhile;
$featured_content_properties.='';
$featured_content_properties.='';
$featured_content_properties.='';
$featured_content_properties.='';
$featured_content_properties.=endif;wp_reset_query();
$featured_content_properties.='';
$featured_content_properties.='';
返回$featured\u content\u属性;
}
添加快捷码(“最新内容属性”、“最新内容属性函数”);
任何帮助都将不胜感激 为什么不创建一个文件,即featured-properties.php并粘贴您的工作代码:-
$currency = get_field('currency', 'options');
$args = array(
'posts_per_page'=> -1,
'post_type' => 'properties',
);
$featured_query = new WP_Query( $args ); ?>
<!-- Featured Properties -->
<h1 class="text-grey"><span class="xstrong">Featured</span> Properties</h1>
<div id="featured-properties">
<div class="container">
<?php if( $featured_query->have_posts() ): $property_increment = 0; ?>
<div id="featured-carousel" class="carousel slide" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner row" role="listbox">
<?php while( $featured_query->have_posts() ) : $featured_query->the_post(); ?>
<?php if($property_increment==0 || $property_increment%3==0 ){ echo '<div class="item '.(($property_increment==0)?'active':'').'">'; } ?>
<div class="col-md-4 col-sm-6 col-xs-12 row">
<div class="property-wrapper">
<a href="<?php echo get_permalink(); ?>">
<div class="corner"></div><p class="corner-text"><?php the_field('house_status'); ?></p>
<?php the_post_thumbnail($featured_query->ID, ''); ?>
<div class="property-details">
<h5 class="property-title"><?php the_title(); ?>,</h5>
<h6 class="property-title"><?php the_field('house_town'); ?></h6>
<h6 class="property-type"><?php the_field('house_type'); ?></h6>
<?php $price = number_format(get_field('house_price')); ?>
<h5 class="property-price"><?php echo $currency . $price; ?></h5>
<h5 class="property-bedrooms"><?php the_field('house_bedrooms'); ?><span class="icon-bedrooms"></span></h5>
<h5 class="property-bathrooms"><?php the_field('house_bathrooms'); ?><span class="icon-bathrooms"></span></h5>
<span class="btn btn-white full">More Details</span>
</div>
</a>
</div>
</div>
<?php echo ($property_increment%3==2)?'</div>':''; ?>
<?php $property_increment++; endwhile; ?>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#featured-carousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#featured-carousel" role="button" data-slide="next">
<span class=" glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<?php endif; wp_reset_query(); ?>
</div>
</div><!-- / Featured Properties -->
/**
* Shortcode: Latest Properties
*/
function latest_content_properties_func( $atts ) {
ob_start();
include 'shortcodes/featured-properties.php';
return ob_get_clean();
}
add_shortcode( 'latest_content_properties', 'latest_content_properties_func' );