首页 文章

PHP / Genesis:Genesis循环中的高级自定义字段

提问于
浏览
0

我在创世记中通过合并一个为Wordpress(非创世)制作的代码来实现这一点tutorial .

我取得了一些进展,但我陷入了高级自定义领域 . 例如, <?php the_title(); ?> 实际上调用了PAGE Headers ,而不是自定义帖子's Title. And the other fields (position, telephone, etc) aren't工作 - 他们确定这是我如何将此代码与Genesis合并的问题 .

<?php
/**
 * This file adds the city team template to any Genesis 2.0+ Theme.
 *
 * @author Jim Thornton
 * @package InboundFound
 * @subpackage Customizations
 */ 

/*
Template Name: Team
*/
?>

<?php
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'your_custom_loop' );

function your_custom_loop() { 


                    // Get 'team' posts
                    $team_posts = get_posts( array(
                        'post_type' => 'team',
                        'posts_per_page' => -1, // Unlimited posts
                        'orderby' => 'title', // Order alphabetically by name
                    ) );

                    if ( $team_posts ):
                    ?>
                    <section class="row profiles">
                        <div class="intro">
                            <h2>Meet The Team</h2>
                            <p class="lead"></p>
                        </div>

                        <?php 
                        foreach ( $team_posts as $post ): 
                        setup_postdata($post);

                        // Resize and CDNize thumbnails using Automattic Photon service
                        $thumb_src = null;
                        if ( has_post_thumbnail($post->ID) ) {
                            $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'team-thumb' );
                            $thumb_src = $src[0];
                        }
                        ?>
                        <article class="col-sm-6 profile">
                            <div class="profile-header">
                                <?php if ( $thumb_src ): ?>
                                <img src="<?php echo $thumb_src; ?>" alt="<?php the_title(); ?>, <?php the_field('team_position'); ?>" class="img-circle">
                                <?php endif; ?>
                            </div>

                            <div class="profile-content">
                                <h3><?php the_title(); ?></h3>
                                <p class="lead position"><?php the_field('team_position'); ?></p>
                                <?php the_content(); ?>
                            </div>

                            <div class="profile-footer">
                                <a href="tel:<?php the_field('team_phone'); ?>"><i class="icon-mobile-phone"></i></a>
                                <a href="mailto:<?php echo antispambot( get_field('team_email') ); ?>"><i class="icon-envelope"></i></a>
                                <?php if ( $twitter = get_field('team_twitter') ): ?>
                                <a href="<?php echo $twitter; ?>"><i class="icon-twitter"></i></a>
                                <?php endif; ?>
                                <?php if ( $linkedin = get_field('team_linkedin') ): ?>
                                <a href="<?php echo $linkedin; ?>"><i class="icon-linkedin"></i></a>
                                <?php endif; ?>
                            </div>
                        </article><!-- /.profile -->
                        <?php endforeach; ?>
                    </section><!-- /.row -->
                    <?php endif; 

}

genesis();

1 回答

相关问题