Php 从wordpress检索帖子图像
我的问题是下面的代码仅在前四篇文章中检索作为附件的图像。对于其他人,它只检索文章标题。每一篇文章的每一端都是相等的,并以相同的方式存储在数据库和wordpress站点的后端。它检索到了前四个,我想是第16篇文章的图片Php 从wordpress检索帖子图像,php,wordpress,image,Php,Wordpress,Image,我的问题是下面的代码仅在前四篇文章中检索作为附件的图像。对于其他人,它只检索文章标题。每一篇文章的每一端都是相等的,并以相同的方式存储在数据库和wordpress站点的后端。它检索到了前四个,我想是第16篇文章的图片 $myposts = get_posts(array( 'category' => $_POST["kategorija"], 'post_type' => 'post', 'posts_per_page' =&
$myposts = get_posts(array(
'category' => $_POST["kategorija"],
'post_type' => 'post',
'posts_per_page' => -1
)
);
?>
<ul>
<?php
foreach ( $myposts as $post ) : setup_postdata( $post );
$title = $post->post_title;
$date = $post->post_date;
$content = $post->post_content;
$status = $post->post_status;
?>
<li>
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo wp_get_attachment_image( $attachment->ID, 'thumbnail' );
}
}
?>
<h2><?php echo $title; ?> </h2>
<form enctype="multipart/form-data" action="oglas.php" method="POST">
<input type="hidden" name="idKategorije" value="<?php echo $post->ID; ?>" />
<input type="submit" value="selektuj" />
</form>
</li>
<?php
endforeach; ?>
</ul>
$myposts=get\u posts(数组)(
'category'=>$\u POST[“kategorija”],
“post_type”=>“post”,
“每页帖子”=>-1
)
);
?>
-
既然你已经在你的第一个get_帖子中得到了帖子,我不知道;我不明白你为什么需要另一个
这是法典中的:
====
显示当前帖子的附件[编辑]
在循环内执行此操作(其中$post->ID可用)
我很困惑。你为什么有两个论点?你不是在寻找“'category'=>$\u POST[“kategorija”]”中所有帖子的附件吗?如果是的话,为什么是第二个论点?我不明白第二个论点是什么?这篇$_帖子[“kategorija”]是我从android应用程序传递的类别(ID)的编号。。我不能把它硬编码在某个特定的号码上@user2197029如果您已经有帖子,为什么需要这个$args=array('post\u type'=>'附件','numberposts'=>-1,'post\u status'=>null,'post\u parent'=>$post->ID);首先,我检索文章,然后在foreach循环中遍历它们,然后通过post->ID获取定义的选项数组上的参数。如果你知道答案,请告诉我@user2197029但您也使用了$attachments=get_posts@用户2197029
<?php
$args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' =>'any', 'post_parent' => $post->ID );
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo apply_filters( 'the_title' , $attachment->post_title );
the_attachment_link( $attachment->ID , false );
}
}
?>