Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wordpress post gallery函数不显示帖子数量_Wordpress_Image_Printing - Fatal编程技术网

wordpress post gallery函数不显示帖子数量

wordpress post gallery函数不显示帖子数量,wordpress,image,printing,Wordpress,Image,Printing,嗨,我有我在content-gallery.php中创建的代码 但是当我使用printf来显示帖子中的照片数量时,却没有显示出来 一定是印刷品 [此邮件库包含9张照片。] 但是不起作用。为什么? 什么时候我犯了错误 <?php $the_images = get_children( array( 'post_parent' => $post->ID, // Pass the ID of a post or Page to get its children. Pas

嗨,我有我在content-gallery.php中创建的代码 但是当我使用printf来显示帖子中的照片数量时,却没有显示出来

一定是印刷品 [此邮件库包含9张照片。] 但是不起作用。为什么? 什么时候我犯了错误

<?php

$the_images = get_children( array(
    'post_parent'   => $post->ID, // Pass the ID of a post or Page to get its children. Pass 0 to get attachments without parent. Pass null to get any child regardless of parent.
    'post_mime_type'=> 'image', // A full or partial mime-type, e.g. image, video, video/mp4, which is matched against a post's post_mime_type field.
    'post_type'     => 'attachment',
    'orderby'       => 'menu_order',
    'order'         => 'ASC',
    'numberposts'   => 999
));

if ( !empty($the_images) ) {
    $the_total_images = count($the_images);
    $the_images       = array_slice($the_images, 0, 10); // prin_r form 0 to 10 images
?>

<p><strong>
    <?php printf (_n('This Post Gallery Contains %s Photo.', 'This Post Gallery Contains %s Photos.', $the_total_images, 'the-bootstrap'), $the_total_images); ?>
</strong></p>

<?php } ?>
尝试使用sprintf而不是printf

另外,确保在使用函数时没有空格。在括号内使用空格是可以的,但是在printf中使用空格是一种不好的做法,大多数情况下都会出现错误或不起作用。

您正在检查图片是否为空。如果为空,则永远不会设置$the_total_images

我也不明白你对数组的用法。只有10个职位肯定会更有效率

我是这样做的:

<?php
global $post;

$the_images = get_posts( array(
    'post_parent'    => $post->ID,
    'post_mime_type' => 'image',
    'post_type'      => 'attachment',
    'post_status'    => 'any',
    'orderby'        => 'menu_order',
    'order'          => 'ASC',
    'posts_per_page' => -1,
) );

$the_total_images = ( $the_images ) ? count( $the_images ) : 0;
$image_count_text = sprintf( _n( 'This Post Gallery Contains %s Photo.', 'This Post Gallery Contains %s Photos.', $the_total_images, 'the-bootstrap' ), $the_total_images); ?>

<p><strong><?php echo $image_count_text; ?></strong></p>
$图片总数不再取决于get_帖子的结果。我让它加载所有图像附件,但我认为如果您只使用10,可以找到更好的解决方案。

您是否尝试过使用sprintf而不是printf?