如何计算在关系字段中添加的帖子。关系字段是一个插件(http://www.advancedcustomfields.com/docs/field-types/relationship/)
在我的管理员中,我创建了一个元框,用于将其他帖子类型的帖子链接到我的帖子。请参见下面链接中的图片
http://i.imgur.com/PFFY8.jpg
字幕和预告片
如何获取附加到关系字段的帖子数量。
例如:如果关系字段有4篇文章添加到站点的选项卡中,我希望能够获得文章的数量
例如:拖车(1)-显示在前端。
类似的内容(cinemagia.ro/filme/avatar-2-578279/)
要检索帖子并显示到我的主题中,我使用
<?php if(get_field(\'trailere_filme\') != ""){foreach(get_field(\'trailere_filme\') as $post_object): ?>
<div class="box-trailere">
<div class="trailer-img">
<a href="<?php echo get_permalink($post_object->ID); ?>" rel="bookmark" title="<?php printf(__(\'Trailer film %s\', \'kubrick\'), the_title_attribute(\'echo=0\')); ?>">
<span class="tip"><?php echo get_field( \'tip\', $post_object->ID ); ?></span>
<span class="trai-hov"></span>
<img src="http://img.youtube.com/vi/<?php echo get_field( \'trailer\', $post_object->ID ); ?>/<?php echo get_field( \'img_trailer\', $post_object->ID ); ?>" alt="Trailer <?php echo get_the_title($post_object->ID) ?>" title="Trailer <?php echo get_the_title($post_object->ID) ?>"></a>
<span class="duration"><?php echo get_field( \'time\', $post_object->ID ); ?></span>
</div>
<span class="trailer-title"><a href="<?php echo get_permalink($post_object->ID); ?>" title="Trailer <?php echo get_the_title($post_object->ID) ?>"><?php echo get_the_title($post_object->ID) ?></a></span>
</div>
<?php endforeach;}else{?>
<div class="no-trailer">Acest film nu are trailer.</div>
<?php } ?>
以及与post相关的标签
在我的hteme中,我使用:
<?php
$orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
\'tag__in\' => $tag_ids,
\'post__not_in\' => array($post->ID),
\'post_type\'=> \'stiri\',
\'posts_per_page\'=>1, // Number of related videos that will be shown.
\'caller_get_posts\'=>1
);}
$recentPosts = new WP_Query($args);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<div class="sidebar-titlu"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div>
<div class="sidebar-stiri">
<img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=60&w=90&zc=1" alt="" title="<?php the_title(); ?>" />
<?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__(\'Permanent Link to %s\', \'kubrick\'), the_title_attribute(\'echo=0\')); ?>">...detalii</a>
</div>
</div>
<?php endwhile; ?>
谢谢