Onbeperkte $1.99 domeinnamen - wij gebruiken goDaddy
Aangedreven door MaxBlogPress

De Houwer van Wordpress #1 - query_posts | De Fouten Blogging van JTPRATT
De Fouten van Blogging van JTPratt


Huis “ Wordpress Houwer #1 - query_posts



De Houwer van Wordpress #1 - query_posts

452 meningen -

Gepost in:

het beeld van de blog-opstellingscategorie wordpress categoriebeeld
452 meningen


Gelieve van nota te nemen: Deze pagina werd oorspronkelijk geschreven in het Engels.

De originele post kan worden bekeken hier.

Please note: This page was originally written in English.

The text has been translated using an online service such as Google or Babelfish.

The original post can be viewed here.


Dit is de allereerste post in 30 Houweren Wordpress in de Reeks van 30 Dagen!

Als u Wordpress - toen gebruikt is dit een reeks u aan referentie op dit ogenblik zult willen! U zou zelfs per e-mail bij de bovenkant van de pagina kunnen willen intekenen. Als u als me uw zieken en vermoeid van het googling van crap die uit het Web gemakkelijke manieren probeert te vinden om bent uw Wordpress blog of website te binnendringen in een beveiligd computersysteem en aan te passen. Ik ga u zeer nuttig en gemakkelijk geven om houwer Wordpress voor een maand elke dag uit te voeren! Ik denk dat het gemakkelijker is om iets in die aard te doen dan een humongous post met meer informatie te schrijven dan u nooit of samenvatting in één zitting zult lezen. In plaats daarvan ga ik u één zeer eenvoudige en gemakkelijke taak geven om elke dag te doen. Afhankelijk van uw vaardigheidsniveau, kunt u of kunt niet een blik bij de post van vorige week willen nemen Hoe te om Uw Eigen Thema te creëren Wordpress.

De Houwer van Wordpress #1 - query_posts

Vandaag in onze allereerste Houwer Wordpress in onze 30 dag „houwer-A“ wij gaan over Wordpress „malplaatjemarkering“ leren query_posts. U kunt lees hier over query_posts in de Codex Wordpress. Om om het even welk van deze voorbeelden te gebruiken moet u PHP codesnippet vóór de „lijn“ plaatsen. Als u weet wat de „niet lijn“ is, volg enkel de verbinding in de vorige paragraaf om uw eigen wordpressthema voor een verklaring tot stand te brengen. Elke codesnippet kan gebruikte om het even welke om het even welke pagina die de „lijn“, zoals uw index.php, category.php, archive.php, tag.php, of search.php gebruikt.

Sluit posten uit die tot een categorie behoren

Misschien wilt u geen posten van een bepaalde categorie die op uw index of een andere archiefpagina verschijnt. U kon dit zelfs gebruiken om bepaalde categorieën te houden van het tonen in onderzoeksresultaten als u aan nodig had. U moet uw categorie „kennen identiteitskaart“ om dit te doen, enkel het terug te winnen van uw dashboard onder „Manage->Categories“, en „- 1 ″ met uw categorie ID# als dit…

<? php
 query_posts („cat=-1“);
?>

You can exclude multple categories like this…

<?php
      query_posts("cat=-1,-2,-3");
?>

Retrieve a Post or Page

To retrieve a particular post you can either call it by ID (listed in your dashboard) or it’s slug like this (use one line of code or the other, not both)…

<?php
query_posts('p=1'); //using post id
query_posts('name=first-post'); //using post slug
?>

You can do the same thing to retrieve pages as well like this…

<?php
query_posts('page_id=7'); //retrieves page 7 only
query_posts('pagename=about'); //retrieves the about page only
?>

When you use those examples it retrieves the entire post. When you are notorious for writing extremely long posts (like I am) you may only want to get a partial post with the “read more” link. This is especialy useful if you’re going ot feature certain posts on your index or other pages. Here’s the code for that…

<?php
query_posts('p=5'); //get post with id of 5
global $more;
$more = 0; //gets partial post with read more link
?>

You know that you can create pages, and you can also create “child pages” like I have on ths site. I have a parent page called “series”, and then all the individual series index pages are children of that page. If you want to get a child page - that’s possible as well, but you can’t call it by id - you have to call it by double-slug as in the example below (parent slug slash child slug).

<?php
query_posts('pagename=parent/child');
?>

Retrieve Post by Certain Authors

If your blog has multiple authors you can retrive them by name or author id like this…

<?php
query_posts('author_name=John');
query_posts('author=3');
?>

Retrieve Every Single Post
Maybe you want to make some kind of an archive page or sitemap. Whether or not you create a page with this query of course depends on how many posts you really have, but inserting this code before the loop will list ever post you have all on one page. While the code below shows all posts on one page, you can change the “-1″ to just 1 post, or 5, or 10, or however many posts you want to display.

<?php
query_posts('posts_per_page=-1');
?>

Change the Order or Sequence of Posts
By default a Wordpress blog shows you posts in a journal fashion or reverse date order. You could choose to instead sort your posts by author or title like this. You could use either the author or title lines.

<?php
query_posts('orderby=author');
query_posts('orderby=title');
?>

Using “orderby” there are many different parameters that you can use like these…

* orderby=author
* orderby=date
* orderby=category
* orderby=title
* orderby=modified
* orderby=menu_order
* orderby=parent
* orderby=ID
* orderby=rand

Retrieve a Post by Time Period

There are many different ways to consruct a query to retrieve certain posts based by date only. Here’s a way to get them for a day of the month…

<?php
query_posts('day=15'); //all posts on the 15th
?>

You could also get them for the current month and year with a query like this…

<?php $current_month = date('m'); ?>
<?php $current_year = date('Y'); ?>

<?php query_posts("cat=22&year=$current_year&monthnum=$current_month&order=ASC"); ?>

Retrieve Posts based on Tags
You can retrieve posts for a specific tag or tags like this (use one line of code at a time only). The first line retrieves posts with a particular tag, the second line is the format for getting posts for multiple tags, but the third line is for getting posts that were tagged in multiple categories. In other words the second line will retrieve all posts tagged as bread all posts tagged as baking. But the third line will get only posts tagged in bread and baking and recipe.

<?php
query_posts('tag=cooking');
query_posts('tag=bread,baking');
query_posts('tag=bread+baking+recipe');
?>

I hope this helps you do a little Wordpress “theme hacking” and customize your blog. If you have any questions about query_posts please comment now, and we’ll see your tomorrow for the next hack!


Tags: , ,

4 Responses to “Wordpress Hack #1 - query_posts”

  1. Mark Wilson Has the following to say...

    I had actually been looking for the one about authors.
    thanks a lot, it been a big help.

    Mark Wilson’s last blog post..I hate the word “nicheâ€

  2. Make Money Blogging Has the following to say...

    Loving the idea even though this one is sort of irrelevant for me, cannot wait for the rest.

  3. Erika Has the following to say...

    Okay… as a wordpress newbie (but someone who chose to dive head-first into WP development… silly me) I can’t tell you how much I value this series that you’re doin! Once I finally get my blog up and running, I’m going to have to toss out a thank-you for helping me so much!

  4. admin Has the following to say...

    @Erika - glad to help! I love comments like this, because it means I made the right decision in starting this series… =

Question or Comment?? Spill it Now...

Jumping for Joy over comments!

We Reward Comments!


We dofollow links, and get your latest blog post as a byline under every new comment from the "CommentLuv" plugin! Top commenters for every month are listed on every page of this site in a sidebar widget linked back to your URL! We would like to reward you for becoming part of our community! Your comment is valuable not only to us, but also all the other readers of this blog!

 


Click to add smilies to your post! = =[] ^=( =(( =(| =)r =|8 =0 =)~ =00 =( =;; =)] =;;;