Wordpress 仅显示当前库中的内容
我想修改下面的脚本,以便发布/显示我当前永久链接库的内容-在当前阶段,尽管它显示所有库的所有图像。我怎样才能改变这个Wordpress 仅显示当前库中的内容,wordpress,Wordpress,我想修改下面的脚本,以便发布/显示我当前永久链接库的内容-在当前阶段,尽管它显示所有库的所有图像。我怎样才能改变这个 <?php $wp_query = new WP_Query(); $wp_query->query( array( 'post_type' => 'galleries', 'posts_per_page' => of_get_option('le_gallery_items'), 'paged' =>
<?php
$wp_query = new WP_Query();
$wp_query->query( array( 'post_type' => 'galleries', 'posts_per_page' => of_get_option('le_gallery_items'), 'paged' => $paged, 'orderby' => 'menu_order', 'order' => 'ASC') );
$mod = 1;
while ( $wp_query->have_posts() ) : $wp_query->the_post();
$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order') );
if(has_post_thumbnail()) {
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
$src = $src[0];
}
else{
foreach ( $attachments as $id => $attachment ) {
$src = wp_get_attachment_url( $id );
}
}
if ($mod % 3 == 0) {
echo ' <div class="gallery-entry-img-last">';
}
else{
echo ' <div class="gallery-entry-img">';
}
?>
如果能得到一些专家的帮助,我们将不胜感激 如果只想获取当前页面的所有图像,请使用以下代码
if ( $images = get_posts(array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image_src( $image->ID, full );
$imageDescription = apply_filters( 'the_description' , $image->post_content );
$imageTitle = apply_filters( 'the_title' , $image->post_title );
//echoing the attachment
echo '<img src="' . $attachmentimage[0] . '" alt="" />';
}
}
else {
echo "No Image";
}
//to exclude feature image use this
get_post_thumbnail_id( $post->ID );
$thumb_ID = get_post_thumbnail_id( $post->ID );
if ( $images = get_posts(array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'image',
'exclude' => $thumb_ID))) //exluding feature image by its ID
if($images=get_posts(数组)(
'post_parent'=>$post->ID,
“post_类型”=>“附件”,
“numberposts”=>-1,
“post_mime_type'=>“image',))
{
foreach($images作为$image){
$attachmenturl=wp\u get\u attachment\u url($image->ID);
$attachmentimage=wp\u get\u attachment\u image\u src($image->ID,full);
$imageDescription=应用过滤器('the_description',$image->post_content);
$imageTitle=apply_过滤器('the_title',$image->post_title);
//附和附件
回声';
}
}
否则{
回声“无图像”;
}
//要排除要素图像,请使用此
获取帖子缩略图id($post->id);
$thumb\u ID=get\u post\u缩略图\u ID($post->ID);
如果($images=get_posts(数组(
'post_parent'=>$post->ID,
“post_类型”=>“附件”,
“numberposts”=>-1,
“post_mime_type”=>“image”,
'exclude'=>$thumb_ID))//通过特征图像的ID排除特征图像
为什么不使用“NextGEN Gallery”之类的插件??我的WordPress安装中有一个内置的图库,但是我目前正在尝试改变它。基本上,在所有的画廊被显示和点击之前,它们会在一个阴影框中单独打开。我已经看到现在修改这个,并有一个画廊在一个新的页面上使用特定的永久链接打开,所以我现在正在寻找一种方法来改变上述代码,以显示这个特定永久链接页面的画廊项目。这个内置的画廊实际上不是WordPress的默认功能(我可以通过'post_type'=>'galleries'
来判断。当您想使用此代码时,您是否在Gallery页面上?如果是这样,只需删除while
循环和$wp_query=new wp_query();$wp_query->query即可。)(…
@IoQ:您的方法如前所述运行得非常好,但我注意到特色图像也正在嵌入。是否有办法更改您的代码以排除特色图像?非常感谢您的专家建议。您是一位真正的专家!非常感谢