/
single.php
135 lines (114 loc) · 4.2 KB
/
single.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* The template for displaying all single posts and attachments
*
* @package WordPress
* @subpackage FoundationPress
* @since FoundationPress 1.0.0
*/
get_header();
$category = get_the_category();
$category_slug = $category[0]->category_nicename;
$edition_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$category_slug'");
$edition_fields = array(
'edition_secondary_feature_headline',
'edition_secondary_feature_content',
'edition_secondary_feature_button',
'edition_secondary_feature_url',
'edition_secondary_feature_background',
'edition_tertiary_feature_content');
foreach($edition_fields as $field){
${$field} = get_field($field, $edition_id);
}
$post_data = get_post($edition_primary_feature);
$feature_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
?>
<div class='row'>
<div id='post_single'>
<div class='large-8 columns'>
<div class="breadcrumbs" xmlns:v="http://rdf.data-vocabulary.org/#">
<?php if(function_exists('bcn_display')){ bcn_display(); }?>
</div>
<?php do_action( 'foundationpress_before_content' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $post_id = get_the_ID(); ?>
<?php wpb_set_post_views(get_the_ID()); ?>
<article <?php post_class() ?> id="post-<?php echo $post_id; ?>">
<header>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php
echo '<p class="byline author">';
echo __( 'By', 'foundationpress' ) . ' ' . get_the_author_nickname() .' | ';
echo '<time class="updated" datetime="'. get_the_time( 'c' ) .'">'. sprintf( __( '%s', 'foundationpress' ), get_the_date()) .'</time>';
echo '</p>';
?>
</header>
<?php do_action( 'foundationpress_post_before_entry_content' ); ?>
<div class="entry-content">
<?php if ( has_post_thumbnail() ) :
$thumb_id = get_post_thumbnail_id($post->ID);
$thumb = wp_get_attachment_image_src($thumb_id, 'large');
$url = $thumb['0'];
$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
?>
<div id="feature_image"><img src="<?=$url?>" alt="<?=$alt?>" width="100%" class="alignnone"></div>
<?php endif; ?>
<?php the_content(); ?>
</div>
<footer>
<?php wp_link_pages( array('before' => '<nav id="page-nav"><p>' . __( 'Pages:', 'foundationpress' ), 'after' => '</p></nav>' ) ); ?>
</footer>
<?php do_action( 'foundationpress_post_before_comments' ); ?>
<?php comments_template(); ?>
<?php do_action( 'foundationpress_post_after_comments' ); ?>
</article>
<?php endwhile;?>
<?php do_action( 'foundationpress_after_content' ); ?>
</div>
<div class='large-4 columns'>
<div id='secondary_feature_container'>
<div id='secondary_feature' style='background-image: url(<?=$edition_secondary_feature_background?>);'>
<div class='content'>
<h2><?=$edition_secondary_feature_headline?></h2>
<p><?=$edition_secondary_feature_content?>
<a href='<?=$edition_secondary_feature_url?>'><?=$edition_secondary_feature_button?></a>
</div>
</div>
</div>
<div id='tertiary_feature'>
<div class='content'><?=$edition_tertiary_feature_content?></div>
</div>
<div id='top_posts'>
<?php
$count = 1;
$args = array(
'posts_per_page' => 4,
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => $category_slug,
'meta_key' => 'wpb_post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
$post_query = new WP_Query($args);
if($post_query->have_posts()){
while($post_query->have_posts()){
$post_query->the_post();
?>
<?php if($count > 3){ break; } ?>
<?php $id = get_the_ID(); ?>
<?php if($id != $post_id){ ?>
<?php get_template_part( 'excerpt', get_post_format() ); ?>
<?php $count++; ?>
<?php } ?>
<?php
}
}
wp_reset_query();
?>
</div>
</div>
<div class='clear_both'></div>
</div>
</div>
<?php get_footer(); ?>