PDA

Zobraziť plnú verziu : Custom Pos Type a archiv (resp. wp_get_archives)



depi
20.09.2010, 12:55
Zdravim,

mam vytvoreny vlastny custom post type "news", ktory bude obsahovat novinky a cez custom template ich bude vo frontende zobrazovat.

Novinky by som vsak rad aj chronologicky zobrazoval prostrednictvom vlastneho archivu podobne ako standardne posty. To by este nebol taky problem.

Problem je vsak v tom, ze napriklad ked chcem zobrazit mesacny suhrn noviniek cez <?php wp_get_archives('type=monthly'); ?> to nie jemozne (kedze funkcia wp_get_archives() akosi s custom post typmi nepocita.

Co by ste navrhovali?

JohnnyPea
25.09.2010, 20:31
Tam kde to chceš zobrazovať dáš (parametre pre wp_get_archives ako normálne):

<?php
add_filter('getarchives_where', 'getarchives_cpt');
wp_get_archives('type=monthly');
remove_filter('getarchives_where', 'getarchives_cpt')
?>
Do functions.php v téme:

function getarchives_cpt()
{
return "WHERE post_type = 'news' AND post_status = 'publish'";
}

Taktiež nezabudni modifikovať šablónu date.php respketíve archive.php, aby ti zobrazovalo aj ten "custom post type".
http://codex.wordpress.org/Template_Hierarchy