Como listar todos os posts de seu wordpress geral, por categorias ou tags


Aprenda como como listar todos os posts de seu wordpress geral, por categorias ou tags

Para listar só com  number posts é a quantidade de postagens

<ul>
<?php
global $post;
$args = array( 'numberposts' => 10000);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>

 

Agora se quiser pegar posts da mesma categoria e ordenar, por ASC ou DESC

Asc mais antigos,

e DESC mais novos

use cat =>104 

104 é o numero da categoria

'category_name' => 'html'

html é o nome da categoria,

Use um dos dois

Veja o exemplo

Vou mostrar 10 postagens da categoria 103 e os mais antigos.

<ul>
<?php
global $post;
$args = array( 'numberposts' => 10, 'cat' => 103,'order'=> 'ASC' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>

 

Categoria: wordpress | Tags: , , , , , , | Postado por joemaster em 02/jul/2020

<< Anterior

Próximo >>

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *