…
…
…
Se volete forzare la ricerca solo all’interno di una specifica tipologia di post, ecco la soluzione! Incollate il codice qui sotto all’interno del file functions.php del vostro tema WordPress.
function SearchFilter($query) { if ($query->is_search) { // Insert the specific post type you want to search $query->set('post_type', 'feeds'); } return $query; } // This filter will jump into the loop and arrange our results before they're returned add_filter('pre_get_posts','SearchFilter');
Ricordatevi di cambiare la tipologia del post alla riga 4.…
Nel tutorial di oggi imparerete come limitare i post per pagina nei risultati di ricerca del vostro blog WordPress.
Copiate e incollate il seguente codice all’interno del file functions.php del vostro tema:
function limit_posts_per_search_page() { if ( is_search() ) set_query_var('posts_per_archive_page', 20); } add_filter('pre_get_posts', 'limit_posts_per_search_page'); …
…
…
…
Nel tutorial di oggi imparerete come ottenere un feed RSS e visualizzare i record con un ciclo.
< ?php include_once(ABSPATH . WPINC . '/rss.php'); $feed = 'http://dangayle.com/feed/'; $rss = fetch_feed($feed); if (!is_wp_error( $rss ) ) : $maxitems = $rss->get_item_quantity(3); $rss_items = $rss->get_items(0, $maxitems); if ($rss_items): echo " <ul>\n"; foreach ( $rss_items as $item ) : //instead of a bunch of string concatenation or echoes, I prefer the terseness of printf //(http://php.net/manual/en/function.printf.php) printf(' <li><a href="%s">%s</a> %s </li> …
In questo semplice tutorial WordPress vi mostreremo come creare una funzione che restituisce l’ID della pagina passando come parametro uno slug.
function get_page_id($name) { global $wpdb; // get page id using custom query $page_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE ( post_name = '".$name."' or post_title = '".$name."' ) and post_status = 'publish' and post_type='page' "); return $page_id; } …