在变量中。php,该页面用于显示与产品相关的任何属性。我希望对代码进行一些更改,但不是对所有页面都进行更改,所以我认为只需将其指向创建一个变量函数即可。php,并在自定义循环中调用它。我的问题是如何用变量构造函数。php,放置所有变量。php输入
function{
code from [variable][1].php
}
创建函数后,如何将其插入循环中,使其与每个产品一起打印?
$args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => 4,
);
$featured_query = new WP_Query($args);
if ($featured_query->have_posts()) {
while ($featured_query->have_posts()) {
$featured_query->the_post();
?>
<ul>
<li><?php the_title(); ?></li>
<li><a href="<?php echo get_permalink(); ?>"><?php echo get_the_post_thumbnail($thumbnail->ID, \'thumbnail\'); ?></a></li>
</ul>
<?php
}
wp_resetpostdata();
}
SO网友:Fraggy
您需要在函数中设置这样的函数。php
function my_function(){
//your function in here
include(TEMPLATEPATH . \'[variable][1].php\');
}
然后在你的循环中,你会这样称呼它:
$args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => 4,
);
$featured_query = new WP_Query($args);
if ($featured_query->have_posts()) {
while ($featured_query->have_posts()) {
$featured_query->the_post();
?>
<ul>
<li><?php my_function(); ?></li>
<li><?php the_title(); ?></li>
<li><a href="<?php echo get_permalink(); ?>"><?php echo get_the_post_thumbnail($thumbnail->ID, \'thumbnail\'); ?></a></li>
</ul>
<?php
}
wp_resetpostdata();
}