2013-03-28 23 views
0

我有一个响应儿童主题,我正在写一个插件列出使用响应网格的帖子。WP_Query奇怪的行为与秩序ASC

如果我将命令设置为DESC(在WP_Query中),一切正常,但对于ASC,我遇到了一个非常奇怪的行为。发布后,按升序排列,但我的函数获取后缩略图不再有效。它与DESC一起工作... wp查询如何影响我的功能?!?!?!

这些都是工作的简码:

[myplugin category="0" order="DESC" orderby="date" limit="4"] 
[myplugin category="0" orderby="date" limit="4"] 

,这一次没有:

[myplugin category="0" order="ASC" orderby="date" post_not_in="233" limit="4"] 

这是我用它来获得在后的第一图像的功能:

function my_get_first_image($postID) { 
    $args = array(
     'numberposts' => 1, 
     'post_mime_type' => 'image', 
     'post_parent' => $postID, 
     'post_status' => null, 
     'post_type' => 'attachment', 
    ); 
    $attachments = get_children($args); 
    if ($attachments) { 
     foreach ($attachments as $attachment) { 
     $fullImg = wp_get_attachment_url($attachment->ID, 'full'); 
     $image_attributes = wp_get_attachment_image_src($attachment->ID, 'big') ? wp_get_attachment_image_src($attachment->ID, 'big') : $fullImg; 
     return '<a rel="shadowbox" href="'.$fullImg.'"><img class="nw_front_thumb" src="' . wp_get_attachment_thumb_url($attachment->ID) . '" class="current"></a>'; 
     } 
    } 
    return ''; 
} 

循环有点长,所以我把它粘贴在粘贴文件夹中。正如你可能想通了这个代码是在我的插件:

http://pastebin.com/cYrag67Y

编辑: http://pastebin.com/rw6NWEeV

+0

请张贴循环,好像你有一个奇怪的怪癖 – 2013-03-31 16:19:28

+0

现在我没有访问到文件...将在本傍晚或最坏情况明天。 – user568021 2013-03-31 17:09:52

+0

这里是...我希望这是有道理的.. – user568021 2013-04-01 20:25:00

回答

0

你可以尝试使用:

the_post_thumbnail() 

代替wp_get_attachment_url()

http://codex.wordpress.org/Function_Reference/the_post_thumbnail

我曾经遇到过类似问题的一些问题。与the_post_thumbnail()完美配合。

工作的示例:

$myimage_html = ''; 
$large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large'); 
$myimage_html .= '<a rel="shadowbox" href="' . $large_image_url[0] . '" title="'.the_title_attribute('echo=0').'" >'; 
$myimage_html .= '<img src="'.wp_get_attachment_url(get_post_thumbnail_id($id)).'">'; 
$myimage_html .= '</a>'; 
+0

我编辑了你的文章...我希望你不介意... – user568021 2013-04-02 11:31:00

+0

Nop。您已经使用了我的解决方案并举了一个工作示例。 =) – 2013-04-02 12:08:59