background preloader

WP dev : The Loop, The Query & The Hierarchy

Facebook Twitter

How to exclude some categories from the widget. Exclure une catégorie d'une boucle WordPress. 10 WordPress Template Tags You May Not Know. WordPress is shipped with quite an abundance of Template Tags since its inception.

10 WordPress Template Tags You May Not Know

These Template Tags in WordPress are PHP functions that can be used to output as well as retrieve a piece of data. If you have been developing a WordPress theme, you may be familiar with some of these Template Tags, such as the_title that shows the post title, the_author that shows the name of the post’s author, and the link of the post. WordPress Single Post Templates. I’ve recently released a plugin that is far more robust than the methods outlined below.

WordPress Single Post Templates

It actually duplicates the functionality of WordPress Page Templates, and allows you to create individual post templates, selectable on a per post basis via a dropdown menu. Head over to my WordPress Plugins page and find the “Post Templates Plugin” UPDATED:Austin recommends using a filter in your functions.php file as an alternative to the method below. IMO, his suggestion is much simpler and quite elegant. Here’s the code to add to your theme’s functions.php file. Mastering WP_Query: 10 Useful Examples. Now that we learned almost everything about the WP_Query class, it's time to try out some examples.

Mastering WP_Query: 10 Useful Examples

In this part, we're going to work on 10 different scenarios to utilize the WP_Query class and related functions. It will be a fun exercise and I hope it will be equally educational. Let's begin! Just to make this article be understandable separately from the "Mastering WP_Query" series, I should do a nano-tutorial on creating WordPress loops with the WP_Query class. Function Reference/query posts. Languages: English • Italiano • 日本語 • 中文(简体) • Português do Brasil • (Add your language) Description Note: This function isn't meant to be used by plugins or themes.

Function Reference/query posts

As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination). Any modern WP code should use more reliable methods, like making use of pre_get_posts hook, for this purpose. query_posts() is a way to alter the main query that WordPress uses to display posts.

It should be noted that using this to replace the main query on a page can increase page loading times, in worst case scenarios more than doubling the amount of work needed or more. Comment utiliser la requête WP query pour l’affichage de vos articles - Naxialis : développeur, intégrateur Wordpress freelance. Un template hierarchy pour cibler les pages de commentaires : Posez moi la question n°3. Daniel Roch a posé cette question sur twitter avec le hashtag #WPAide, j’y réponds alors avec du code !

Un template hierarchy pour cibler les pages de commentaires : Posez moi la question n°3

Template hierarchy Le template hierarchy ou la hiérarchie des modèles de WordPress est la façon dont WordPress va choisir le fichier du thème à inclure selon la page visitée. Par exemple un article est habituellement single.php, la page 404 est 404.php, la page d’un mot-clé est tag.php etc Pour rappel, ce graphique (que vous devriez déjà avoir en favori) vous récapitule tous les templates possibles. Question pour un champion Voilà alors la question de Daniel. Le template chargé pour un post restera alors single.php, et non paged.php (qui est là pour les archives uniquement) ni même autre chose. The Loop. Languages: English • Français • Italiano • 日本語 • Português do Brasil • Русский • 中文(简体) • 中文(繁體) • (Add your language) The Loop is PHP code used by WordPress to display posts.

The Loop

Using The Loop, WordPress processes each post to be displayed on the current page, and formats it according to how it matches specified criteria within The Loop tags. Any HTML or PHP code in the Loop will be processed on each post. When WordPress documentation says "This tag must be within The Loop", such as for specific Template Tags or plugins, the tag will be repeated for each post. For example, The Loop displays the following information by default for each post: You can display other information about each post using the appropriate Template Tags or (for advanced users) by accessing the $post variable, which is set with the current post's information while The Loop is running. For a beginner's look at The Loop, see The Loop in Action.

Custom Page Templates - smashingmagazine. I like to think of WordPress as the gateway drug of web development.

Custom Page Templates - smashingmagazine

Many people who get started using the platform are initially merely looking for a comfortable (and free) way to create a simple website. Some Googling and consultation of the WordPress Codex1 later, it’s done and that should be it. Kind of like “I’m just going to try it once.” However, a good chunk of users don’t stop there. Instead, they get hooked. Luckily, WordPress is built for exactly that. Among the most important tools in the quest for complete website control are page templates. If you want to know how WordPress page templates can help you achieve that, read on. Template Files In WordPress What are we talking about when we speak of templates in the context of WordPress? The slightly longer version: every time someone sends a request to view part of your website, the WordPress platform will figure out what content they want to see and how that specific part of your website should be rendered. 1. 2. 1.