PHP - Como mostrar numero limitado de post en mi tamplate

 
Vista:
Imágen de perfil de Braulio

Como mostrar numero limitado de post en mi tamplate

Publicado por Braulio (1 intervención) el 17/03/2015 14:24:37
Hola, tengo un problema en utilizar (posts_per_page) hacia un (custom fields).

Tengo un custom fields llamado (selector_de_noticias), este fields es un relationship, que se encarga de relacionarme dos Custom Post Types entre si, mis Custom Post Types son Eventos (eventosae) y Noticias (noticiasparaeventos).

Bueno mi problema es que logro mostrar el (custom fields) [mostrandome las Noticias relacionadas al Evento], pero no quiero que me aparezcan todas las noticias, sino solo 3 noticias, que luego yo le agregaria (no se como) un "Ver mas Noticias", sin mas, aca les dejo el codigo que estoy utilizando para mostrar las Noticias Relacionadas a uno de mis Eventos:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
 
 
$posts = get_field('selector_de_noticias');
 
if( $posts ): ?>
 
    <div id="columna_evento_1">
 
    <div id="div_titulo_noticias_evento">
    <a class="titulo_noticias_evento">Noticias del Evento</a>
    </div>
 
    <div id="div_noticias_evento">
 
    <?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
 
        <li>
 
           <a class="titulo_noticia_evento_link" href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
        <div class="imagen_noticia_evento"> <?php echo get_the_post_thumbnail( $p->ID ); ?> </div>
        <p><?php echo extracto_noticia($p); ?></p>
 
        </li>
 
    <?php endforeach; ?>
 
    </div>
    </div>
 
<?php endif;?>


Y aca les dejo lo que deberia introducir, es solo que no se como adaptarlo a mi código:



1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
 
// get only first 3 results
$ids = get_field('selector_de_noticias', false, false);
 
$query = new WP_Query(array(
    'post_type'          => 'ACA NO SE SI VA   noticiasparaeventos   Ó   eventosae   IGUAL CON NINGUNO DE LOS DOS ME FUNCIONA',// Ó no se como adaptarlo a mi código
    'posts_per_page'    => 3,
    'post__in'        => $ids,
    'post_status'        => 'any',
    'orderby'            => 'rand',
));
 
?>


Espero me puedan ayudar, muchisimas gracias de ante mano.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder