Through the system of categories and tags of WordPress, it is very easy to display content other than the default. After the many themes "Magazine" displaying items in a certain category or key word many blog have begun to use them. But some WordPress users will want to also create this effect magazine on their blog by posting the very specific content. In this note we show how to create a real module and how the "insert in your side column or your homepage.
We will use simply the "query_posts" of WordPress and specify the different elements we need. Please have your FTP client and a text editor. Prepare also the different categories (the names and identifying in some cases) or keywords in your blog (identifier). The title and content will not cut the damaged graphics architecture and usability of your blog.

Query_posts to create an outer loop to loop behind WordPress. This loop is custom rather interesting since it can be inserted as many times as you want. Fully customizable it is very easy to display any content of your blog and optimize the display and navigation within your blog. Your visitors will be pleased to navigate freely in certain sections. Query_posts is mainly used in the themes "Magazine" or in modules such as "Featured" or "Getting ahead".
This module is really simple and easy to insert in any blog. You simply create a category or key word (recommended) and then display the contents anywhere on your blog. Moreover, thanks to a simple function, you can change the number of characters to display your title or brief description of your items.
Several settings are possible and thus allow better filtering of content. Each parameter can be combined without increasing Saisse display kegs specific elements of your blog. In this article we'll use some variables simple and easy to integrate.
- Display categories (cat)
- Display keyword (tag)
- Use the first part of the article (more comprehensive)
- An excerpt from the title and content (strlen and content_rss)
- Closing the loop (r eset_query)
- The display order of items (orderby)
Let us develop your module. We will first create the feedback loop including the categories or keywords to display. To display the contents of a single category simply paste the following code by changing the ID property of your class and number of items to display. The title and content are complete. To find the ID of your categories, go to the tab "Categories" to your terminal and fly one you want to use. At the end of the address displayed you will find the ID of your category (cat_ID = 149)
<div class="featured"> <? php query_posts ( 'cat = 149 & showposts = 2 & orderby = rand'); global $ more; $ more = 0;?> <while (have_posts ()): the_post (); > <p class="titre"> <a href = "<? php the_permalink ();?>" title = "<? php the_title ();?>"> <? php the_title ();?> </ a > </ p> <p class="content"> <? php the_content ();?> </ p> <? php endwhile; <? php wp_reset_query ();?> </ div> To view more categories you just add a comma and insert a new identifier of another class. Replace the line containing the "query_posts" by it.
<? php query_posts ( 'cat = 75.149 & showposts = 2 & orderby = rand');?>
Now we will display items containing specific keywords, one or more. With the basic parameters of WordPress we can display items containing one or more keywords.
<div class="featured"> <? php query_posts ( 'tag = info & showposts = 2 & orderby = rand');?> <while (have_posts ()): the_post ();?> <p class="titre"> <a href = "<? php the_permalink ();?>" title = "<? php the_title ();?>"> <? php the_title ();?> </ a> </ p> <p class="content"> <? php the_content ();?> </ p> <? php endwhile;> <? php wp_reset_query ();?> </ div>
To see more keywords simply add a comma and insert another key word. Replace the line containing the "query_posts" by it.
<? php query_posts ( 'tag = info, tips & showposts = 2 & orderby = rand');?>
Having seen how to display items from your classes and your keywords, we'll just see how combine these two parameters and optimize the display of content. We'll display the items in the category "75" and "149" containing the keywords "information" and "tricks". Replace the line containing the "query_posts" by it.
<? php query_posts ( 'tag = info, tips & cat = & 75.149 showposts = 2 & orderby = rand');?>
Optimize your reasons for not hitting the ergonomics of your blog is quite easy actually. Instead of displaying the title and content to track, we'll add code "cutting" the title and content after a certain number of characters. For the contents of the article we will simply use the "content_rss" and specify the number of words to display.
<div class="featured"> <? php query_posts ( 'tag = info, tips & cat = & 75.149 showposts = 2 & orderby = rand');?> <while (have_posts ()): the_post ();?> <p class="titre"> <a href = "<? php the_permalink ();?>" title = "<? php the_title ();?>"> <? php if (strlen ($ post-> post_title)> 40) (echo substr ($ post-> post_title, 0.40 ).'...';} else (the_title ();)> </ a> </ p> <p class="content"> <? php the_content_rss ('', TRUE,'', 60);?> </ p> <? php endwhile;> <? php wp_reset_query ();?> </ div>
After the development of this module, you must also consider its appearance and of course its location. On his site I can only advise you according to your theme.
. featured (width: 400px; height: auto; color: # 598494; font-family: Arial; font-size: 11px; text-align: left;). title (margin: 0px; font-style: normal font - size: 20px;). As a,. As a: visited (color: # 4e6c78; text-decoration: none; font-size: 20px;). As a: hover,. as a: active (color: # 6f94a2; text-decoration: none; font-size: 20px;)


For what I've tested this function, the problem is that
does not work correctly ducoup when several loop, the results of the first loop impacting the results of the second.
To avoid this you should use this code:
query('vos filtres');$ids = array();
while ($f->have_posts()) : $f->the_post(); ?>
which recreates every time a new function.
missing a piece of code
$f = new WP_Query();$f->query('showposts=5&offset=1&cat=-172,-173');$ids = array();
while ($f->have_posts()) : $f->the_post();
It should be better
Thank you very much for your help.
I'm "playing" with your code and modify it to give my home exactly the form that interests me: kind of a newspaper page.
So I created a vertical split with one section left home all the way up, and your right I insert loop with several sub divisions.
For the first (top and right then), I would like to add a summary of an article that served as my home but I want my visitors to read because it explains the background of my subject. How to call a specific article loop with your query?
Then I'll put your loop calling a class.
Then I'll put a html element for presenting the book of the month and, finally, your loop tag.
To give an appearance "log" that you advise me as manager?
Again thank you to think of dummies php.
Another small question.
How to recover the function that displays the titles of recent articles that are available in widgets?
Thank you.
Thank you for this great tutorial I am going to test AC on.