{"id":418,"date":"2015-03-04T13:30:42","date_gmt":"2015-03-04T13:30:42","guid":{"rendered":"http:\/\/pixert.com\/blog\/?p=418"},"modified":"2017-01-09T02:49:47","modified_gmt":"2017-01-09T02:49:47","slug":"many-attachment-wordpress-post","status":"publish","type":"post","link":"https:\/\/pixert.com\/blog\/many-attachment-wordpress-post\/","title":{"rendered":"How many attachment in a WordPress post has?"},"content":{"rendered":"<p><a href=\"http:\/\/pixert.com\/blog\/how-to-upgrade-wordpress\/wordpresslogo\/\" rel=\"attachment wp-att-25\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"25\" data-permalink=\"https:\/\/pixert.com\/blog\/how-to-upgrade-wordpress\/wordpresslogo\/\" data-orig-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?fit=498%2C113&amp;ssl=1\" data-orig-size=\"498,113\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"WordPress &#8211; the logo\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?fit=300%2C68&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?fit=498%2C113&amp;ssl=1\" class=\"size-full wp-image-25 aligncenter\" src=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?resize=498%2C113\" alt=\"\" width=\"498\" height=\"113\" srcset=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?w=498&amp;ssl=1 498w, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?resize=300%2C68&amp;ssl=1 300w\" sizes=\"auto, (max-width: 498px) 100vw, 498px\" \/><\/a><\/p>\n<p>There was a case where a client wanted to remove previous and next arrows in attachment images slider. The problem was that she wanted to remove arrows when<strong> only one image in WordPress attachment<\/strong>, \u00a0arrows still showing when there&#8217;re\u00a0more than one images.<\/p>\n<p>The solution was to found\u00a0out how many attachment in a WordPress post.<!--more--> There is no conditional tag for this purpose, so we create lines of code. Add following code to WordPress template, for example single.php<\/p>\n<pre class=\"brush: plain; title: Code Block; notranslate\" title=\"Code Block\">\r\n\r\n&lt;?php\r\n\r\n$attachments = get_children(array('post_parent'=&gt;$post-&gt;ID));\r\n$nbImg = count($attachments);\r\nif ($nbImg == 1) {\r\necho 'There is'.$nbImg.' picture on this post.';\r\n}\r\nif ($nbImg &gt; 1) {\r\necho 'There are '.$nbImg.' pictures on this post.';\r\n}\r\n?&gt;\r\n\r\n<\/pre>\n<p>If there is one image, text should read &#8216;There is 1 picture on this post&#8217;<br \/>\nIf there is more than one image, text should read &#8216;There are 2 pictures on this post<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2015\/02\/wordpressattachmentnum.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"433\" data-permalink=\"https:\/\/pixert.com\/blog\/many-attachment-wordpress-post\/wordpressattachmentnum\/\" data-orig-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2015\/02\/wordpressattachmentnum.jpg?fit=1334%2C848&amp;ssl=1\" data-orig-size=\"1334,848\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"wordpressattachmentnum\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2015\/02\/wordpressattachmentnum.jpg?fit=300%2C191&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2015\/02\/wordpressattachmentnum.jpg?fit=1024%2C651&amp;ssl=1\" class=\"alignright size-large wp-image-433\" src=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2015\/02\/wordpressattachmentnum-1024x651.jpg?resize=620%2C394\" alt=\"wordpressattachmentnum\" width=\"620\" height=\"394\" srcset=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2015\/02\/wordpressattachmentnum.jpg?resize=1024%2C651&amp;ssl=1 1024w, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2015\/02\/wordpressattachmentnum.jpg?resize=300%2C191&amp;ssl=1 300w, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2015\/02\/wordpressattachmentnum.jpg?w=1334&amp;ssl=1 1334w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There was a case where a client wanted to remove previous and next arrows in attachment images slider. The problem was that she wanted to remove arrows when only one image in WordPress attachment, \u00a0arrows still showing when there&#8217;re\u00a0more than one images. The solution was to found\u00a0out how many attachment in a WordPress post.<\/p>\n","protected":false},"author":1,"featured_media":433,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[148],"class_list":["post-418","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-wordpress-attachment"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2015\/02\/wordpressattachmentnum.jpg?fit=1334%2C848&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1pvi1-6K","jetpack-related-posts":[{"id":101,"url":"https:\/\/pixert.com\/blog\/wordpress-click-an-attachment-image-to-view-next-image-in-order\/","url_meta":{"origin":418,"position":0},"title":"WordPress: Click an attachment image to view next image in order","author":"Pixel Insert \/ Pixert","date":"May 8, 2011","format":false,"excerpt":"Add the following to the top of attachment.php [php] <?php \/\/ code copied from adjacent_image_link() in wp-include\/media.php $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') )); foreach ( $attachments as $k => $attachment ) if (\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo-300x68.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":255,"url":"https:\/\/pixert.com\/blog\/how-to-add-pinterest-button-on-wordpress-attachment-file\/","url_meta":{"origin":418,"position":1},"title":"How to add Pinterest Button on WordPress Attachment file","author":"Pixel Insert \/ Pixert","date":"August 1, 2012","format":false,"excerpt":"See How to Add Pinterest \"Pin It\" to WordPress for introduction Codes in article above may work for Posts, but there's a little tweak for Pinterest Pin It button on attachment.php to work [php] <div class=\"pinterest\"> <a href=\"http:\/\/pinterest.com\/pin\/create\/button\/?url=<?php the_permalink(); ?>&media=<?php echo wp_get_attachment_url(); ?>&description=<?php the_title(); ?> on <?php bloginfo('url'); ?>\" class=\"pin-it-button\"\u2026","rel":"","context":"In &quot;WordPress&quot;","block_context":{"text":"WordPress","link":"https:\/\/pixert.com\/blog\/category\/wordpress\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2012\/02\/pinterestlogo.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":314,"url":"https:\/\/pixert.com\/blog\/wordpress-add-title-to-img-tag-using-get-the-image-plugin\/","url_meta":{"origin":418,"position":2},"title":"WordPress: Add Title to IMG tag using Get The Image plugin","author":"Pixel Insert \/ Pixert","date":"October 29, 2013","format":false,"excerpt":"Get The Image plugin from Justin Tadlock is awesome, a script that can grab an image by custom field input, WordPress' featured image, post attachment, or extracting it from the post's content. Recently, someone asked about how to add Title to IMG tag. We know ALT attributes in IMG tag,\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/10\/screenshot-1.jpg?fit=1138%2C742&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/10\/screenshot-1.jpg?fit=1138%2C742&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/10\/screenshot-1.jpg?fit=1138%2C742&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/10\/screenshot-1.jpg?fit=1138%2C742&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/10\/screenshot-1.jpg?fit=1138%2C742&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":268,"url":"https:\/\/pixert.com\/blog\/wordpress-limit-post\/","url_meta":{"origin":418,"position":3},"title":"WordPress Limit Post","author":"Pixel Insert \/ Pixert","date":"November 30, 2012","format":false,"excerpt":"This function controls the maximum\u00a0amount of characters displayed for an entry on the main page. If the set limit is surpassed, the text on the entry will be chopped\u00a0to that amount of characters, otherwise the content will be showed unchanged. Add following code to functions.php in your theme folder [php]\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo-300x68.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":191,"url":"https:\/\/pixert.com\/blog\/how-to-add-pinterest-pin-it-to-wordpress\/","url_meta":{"origin":418,"position":4},"title":"How to Add Pinterest &#8220;Pin It&#8221; to WordPress","author":"Pixel Insert \/ Pixert","date":"February 14, 2012","format":false,"excerpt":"Pinterest is a vision board-styled social photo sharing website and app where users can create and manage theme-based image collections. Users of Pinterest curate themed image boards, populating them with media found online using the \"Pin It\" button, or uploaded from their computer. Each such item of media is known\u2026","rel":"","context":"In &quot;WordPress&quot;","block_context":{"text":"WordPress","link":"https:\/\/pixert.com\/blog\/category\/wordpress\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3,"url":"https:\/\/pixert.com\/blog\/how-to-create-epub-ebooks-and-transfer-it-to-stanza\/","url_meta":{"origin":418,"position":5},"title":"How to Create ePub ebooks and transfer it to Stanza","author":"Pixel Insert \/ Pixert","date":"March 18, 2011","format":false,"excerpt":"ePub is the Open eBook standard from the International Digital Publishing Forum. Files have the extension \".epub\" Stanza is electronic book reader and book sharing software for iPhone\/iPod Touch and iPad. Here's how you can convert nearly any eBook format to ePub on Windows or Mac OS. We're using free\u2026","rel":"","context":"In &quot;Mac OS&quot;","block_context":{"text":"Mac OS","link":"https:\/\/pixert.com\/blog\/category\/mac-os\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts\/418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/comments?post=418"}],"version-history":[{"count":0,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts\/418\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/media\/433"}],"wp:attachment":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/media?parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/categories?post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/tags?post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}