-
Notifications
You must be signed in to change notification settings - Fork 1
/
content-attachment.php
132 lines (105 loc) · 4.33 KB
/
content-attachment.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
<div id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?>>
<div class="entry-body" class="clearfix">
<?php get_template_part('entry', 'header'); ?>
<div class="entry-content" class="clearfix">
<div class="entry-attachment">
<?php if ( wp_attachment_is_image() ) :
$attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
$counter = 0;
$prev_attachments = array();
$next_attachments = array();
$current_id = 0;
foreach ( $attachments as $k => $attachment ) {
$counter++;
if ( $attachment->ID == $post->ID )
break;
}
$current_id = $k + 1;
$k++;
// If there is more than 1 image attachment in a gallery
if ( count( $attachments ) > 1 ) {
// Back links first
for ($i = 10; $i >= 1; $i--) {
if( isset($attachments[ ($k - $i - 1) ]) ){
$link = array(
'id' => ($k - $i),
'URL' => get_attachment_link( $attachments[ ($k - $i - 1) ]->ID )
);
$prev_attachments[] = $link;
}
}
// Back links first
for ($i = 1; $i <= 10; $i++) {
if( isset($attachments[ ($k + $i - 1) ]) ){
$link = array(
'id' => ($k + $i),
'URL' => get_attachment_link( $attachments[ ($k + $i - 1) ]->ID )
);
$next_attachments[] = $link;
}
}
if ( isset( $attachments[ $k ] ) ){
// get the URL of the next image attachment
$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
} else {
// or get the URL of the first image attachment
$next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
}
} else {
// or, if there's only 1 image attachment, get the URL of the image
$next_attachment_url = wp_get_attachment_url();
}
?>
<div class="attachment-navi">
<?php if ( count( $attachments ) > 1 ) {
foreach($prev_attachments as $key=>$link){
echo " <a href=\"".$link['URL']."\">" . $link['id'] . "</a> ";
}
} ?> <strong><?php echo $current_id; ?></strong>
<?php if ( count( $attachments ) > 1 ) {
foreach($next_attachments as $key=>$link){
echo " <a href=\"".$link['URL']."\">" . $link['id'] . "</a> ";
}
} ?>
</div>
<p class="attachment"><a href="<?php echo $next_attachment_url; ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
$attachment_width = apply_filters( 'twentyten_attachment_size', 900 );
$attachment_height = apply_filters( 'twentyten_attachment_height', 900 );
echo wp_get_attachment_image( $post->ID, array( $attachment_width, $attachment_height ) ); // filterable image width with, essentially, no limit for image height.
?></a></p>
<div id="nav-below" class="navigation clearfix">
<div class="nav-previous"><?php previous_image_link( false ); ?></div>
<div class="nav-next"><?php next_image_link( false ); ?></div>
</div><!-- #nav-below -->
<?php
if ( ! empty( $post->post_parent ) ) {
$parent = $post->post_parent;
} else {
$parent = 0;
}
echo $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = '$parent' AND post_type = 'attachment'" );
?> pictures // <?php echo stf_views(); ?>
<div class="attachment-navi">
<?php if ( count( $attachments ) > 1 ) {
foreach($prev_attachments as $key=>$link){
echo " <a href=\"".$link['URL']."\">" . $link['id'] . "</a> ";
}
} ?> <strong><?php echo $current_id; ?></strong>
<?php if ( count( $attachments ) > 1 ) {
foreach($next_attachments as $key=>$link){
echo " <a href=\"".$link['URL']."\">" . $link['id'] . "</a> ";
}
} ?>
</div>
<?php else : ?>
<a href="<?php echo wp_get_attachment_url(); ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php echo basename( get_permalink() ); ?></a>
<?php endif; ?>
</div><!-- .entry-attachment -->
<?php the_content( stf_more( ) ); ?>
<?php stf_entry_pages(); ?>
<?php if( is_single() ) { stf_related_posts(); } ?>
</div><!-- .entry-content -->
<?php get_template_part('entry', 'footer'); ?>
</div>
</div><!-- #post-<?php the_ID(); ?> -->
<?php stf_comments(); ?>