Mám tuto stránku, kde zobrazuji všechny přílohy příspěvku.
Toto je kód:
<?php
$args = array(
'post_type' => 'attachment',
'post_status' => 'published',
'posts_per_page' =>25,
'post_parent' => null, // Post-> ID;
'numberposts' => null,
);
$attachments = get_posts($args);
$post_count = count ($attachments);
if ($attachments) {
foreach ($attachments as $attachment) {
echo "<div class=\"post photo col3\">";
$url = get_attachment_link($attachment->ID);// extraigo la _posturl del attachmnet
$img = wp_get_attachment_url($attachment->ID);
$title = get_the_title($attachment->post_parent);//extraigo titulo
echo '<a href="'.$url.'"><img title="'.$title.'" src="'.$img.'"></a>';
echo "</div>";
}
}
?>
Nyní mám post_types 'post', 'page' a 'videos'. Dostávám všechny, ale chci zobrazit pouze příspěvek post_type. Jak mohu vyloučit post_type videa?
Dík!
$posts = get_posts( array( 'post_type' => 'post', 'posts_per_page' => -1 ) );
foreach ( $posts as $post ) {
$attachments = get_children( array (
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_per_page' => 25
), ARRAY_A );
if( $attachments ) {
//continue with what you were doing
}
}
jednoduše vložte následující kód kdekoli ve vašem souboru a přílohy budou zobrazeny.
$ args = array ( 'post_type' => 'příloha', 'numberposts' => null, 'post_status' => null, 'post_parent '=> $ post-> ID ); $ přílohy = get_posts ($ args); if ($ přílohy) { foreach ($ přílohy jako $ attachment) { echo apply_filters ('the_title' , $ attachment-> post_title); the_attachment_link ($ attachment-> ID, false), } }