Lascio una bella lista che terrò aggiornata, di trucchi per WordPress da utilizzare via PHP e MySQL, possono essere sempre utili, soprattutto agli sviluppatori come me 🙂 yahoo!
Codice per mostrare i post recenti
(sostituire il 5 con il numero di post desiderato)
1 2 3 4 5 6 |
<?php query_posts('showposts=5'); ?> <ul> <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile;?> </ul> |
Come mostrare le pagine o gli articoli aggiornati di recente
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php $today = current_time('mysql', 1); $howMany = 5; //Number of posts you want to display if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")): ?> <h2><?php _e("Aggiornamenti Recenti"); ?></h2> <ul> <?php foreach ($recentposts as $post) { if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID); echo "<li><a href='".get_permalink($post->ID)."'>"; the_title(); echo '</a></li>'; } ?> </ul> <?php endif; ?> |
Come visualizzare i commenti recenti di WordPress
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 |
<?php global $wpdb; $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 10"; $comments = $wpdb->get_results($sql); $output = $pre_HTML; $output .= "\n<ul>"; foreach ($comments as $comment) { $output .= "\n<li>".strip_tags($comment->comment_author) .":" . "<a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"on " . $comment->post_title . "\">" . strip_tags($comment->com_excerpt) ."</a></li>"; } $output .= "\n</ul>"; $output .= $post_HTML; echo $output;?> |
Visualizzare elenco categorie WordPress
1 2 3 4 |
<h2>Categorie</h2> <ul> <?php wp_list_cats('sort_column=name'); ?> </ul> |
Elenco categorie WP in menu a tendina dropdown
1 2 3 4 5 6 |
<form action="<?php bloginfo('url'); ?>/" method="get"> <?php $select = wp_dropdown_categories('show_option_none=Seleziona una categoria&show_count=1&orderby=name&echo=0'); $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select); echo $select; ?> <noscript><input type="submit" value="Mostra" /></noscript> </form> |
Codice per visualizzare l’archivio di WordPress
1 2 3 4 |
<h2>Archivi</h2> <ul> <?php wp_get_archives('type=monthly'); ?> </ul> |
Oppure in un menu a tendina
1 2 3 |
<select name=\"archive-dropdown\" onChange='document.location.href=this.options[this.selectedIndex].value;'> <option value=\"\"><?php echo attribute_escape(__('Seleziona Periodo')); ?></option> <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select> |
Mostra Avatar
(Solo da WordPress 2.5 in poi)
1 |
<?php if(function_exists(’get_avatar’)){ echo get_avatar($comment, ‘50?);} ?> |
Blogroll Links
1 2 3 |
<ul> <?php get_links_list(); ?> </ul> |
Admin Meta
1 2 3 4 5 6 7 |
<ul> <?php wp_register(); ?> <li><?php wp_loginout(); ?></li> <li><a href="http://www.wordpress.org/">WordPress</a></li> <?php wp_meta(); ?> <li><a href="http://validator.w3.org/check?uri=referer">XHTML</a></li> </ul> |
Tags
1 |
<?php the_tags(); ?> |
Tags Cloud
1 |
<?php wp_tag_cloud('smallest=8&largest=36&'); ?> |
Programmatore WordPress Esperto WooCommerce
Sono l’autore di questo blog con tanti trucchi e guide su WordPress e WooCommerce.