我正在尝试从自定义帖子中提取信息,将其输入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>
我最终弄清楚了。对于未来的开发人员来说,更容易删除所有功能并执行此操作
$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>