我正在尝试从自定义帖子中提取信息,将其输入foreach循环,然后将其回显到重复面板中的函数中。在某个时候,我猜想函数声明正在重新声明(它不在任何其他文件中,我对此有100%的信心),因为我不断收到“无法重新声明以前在同一文件路径php 43中声明的output_member()” “。
感谢您的帮助。
function output_team_members( $title, $id, $position ) {
$post_thumbnail = has_post_thumbnail( $id );
if ( $post_thumbnail == true ) {
$image = get_the_post_thumbnail_url( $id );
} else {
$image = get_stylesheet_directory_uri() . '/dist/assets/images/avatar.png';
}
$first = explode( ' ', $title, 2 );
$first_name = $first[0];
$position_title = get_field( 'person_title', $id );
$job_summary = get_field( 'job_summary', $id );
echo
"<li class='is-active orbit-slide'>
<figure class='orbit-figure'>
<div class='top'>
<h4>Meet $first_name</h4>
<p>$job_summary</p>
</div>
<div class='bottom'>
<img src=$image>
<h5>$title</h5>
<p>$position_title</p>
<button class='orbit-previous'></button>
<button class='orbit-next'></button>
</div>
</figure>
</li>";
}
$team_members = get_posts(
[
'post_type' => 'team-member',
'post_status' => 'publish',
'numberposts' => -1,
]
);
/** Grabs information about the post types team-member */
function output_member( $team_members ) {
foreach ( $team_members as $member ) {
output_team_members( $member->post_title, $member->ID, $member->post_content );
}
}
?>
<div class="orbit">
<div class="orbit-wrapper">
<div class="orbit-container">
<?php output_member( $team_members ); ?>
</div>
</div>
</div>
答案 0 :(得分:1)
我最终弄清楚了。对于将来的开发人员来说,将所有功能全部删除就更容易了,只需执行此操作
$team_members = get_posts(
[
'post_type' => 'team-member',
'post_status' => 'publish',
'numberposts' => -1,
]
);
?>
<div class="orbit">
<div class="orbit-wrapper">
<div class="orbit-container" style="height: 500px;">
<?php
foreach ( $team_members as $member ) {
$title = $member->post_title;
$id = $member->ID;
$positon = $member->post_content;
$post_thumbnail = has_post_thumbnail( $id );
if ( true === $post_thumbnail ) {
$image = get_the_post_thumbnail_url( $id );
} else {
$image = get_stylesheet_directory_uri() . '/dist/assets/images/avatar.png';
}
$first = explode( ' ', $title, 2 );
$first_name = $first[0];
$position_title = get_field( 'person_title', $id );
$job_summary = get_field( 'job_summary', $id );
echo
"<li class='orbit-slide'>
<figure class='orbit-figure'>
<div class='top'>
<h4>Meet $first_name</h4>
<p>$job_summary</p>
</div>
<div class='bottom'>
<img src=$image>
<h5>$title</h5>
<p>$position_title</p>
</div>
</figure>
</li>";
}
?>
<button class='orbit-previous'></button>
<button class='orbit-next'></button>
</div>
</div>