go41

Re: How to get posts to list in order, depending on value of custom field :: Reply by Joern

von Joern am 30. Mai. 2010 | Keine Kommentare

first I should know if you use a custom category.php for your categories?

Most themes just have an archive.php for any kind of archive, be it category, date or tag etc.

Using a template for categories only you need something like a copy of archive.php named category.php

In your case I would create a category template for your ‚hire‘ category, done by creating a copy of archive.php or if you have category.php and name it category-ID.php, where ID has to be the number of your hire category, ie: category-15.php for a category with the ID=15

Now whenever you click on a link in your site going to /hire/ wordpress will use this template.
the query to sort by a value of a custom field looks like this
query_posts(‚orderby=meta_value&meta_key=YOUR-METAKEY-NAME&order=DESC‘);
so before the line:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
you add:

<?php query_posts(‚orderby=meta_value&meta_key=YOUR-CUSTOMFIELD-NAME&order=DESC‘); ?>
this should sort your posts by the value of your custom field
____________________
you find me on Google+, Twitter and Facebook

(von: Joern)

Hier noch 5 weitere Ergebnisse dieses Threads:

How to get posts to list in order, depending on value of custom field

26. Mai. 2010 (von: adamwork)

Hi allI'm using wordpress to act as a CMS for listing products. See development so far here:http://www.concept-ents.com/hire/disco- ... hting-hireThe price column, on the left hand side, is generated by a custom field "Price"How can I set it, so that each…

Re: How to get posts to list in order, depending on value of custom field :: Reply by adamwork

13. Jun. 2010 (von: adamwork)

Hi JoernWhat I have done, is to create a page template, for example this page here:http://www.concept-ents.com/hire/disco- ... pment-hire has a template.Then for each section, I have this in my code:Code:<?php if (have_posts()) : ?>    ... Weiterlesen →

Re: How to get posts to list in order, depending on value of custom field :: Reply by master

13. Jun. 2010 (von: master)

imho the way to add the sort code for a custom field with the name 'YOUR-CUSTOMFIELD-NAME' should work like this for each sectionCode:<?php query_posts('showposts=20&cat=26&orderby=meta_value&meta_key=YOUR-CUSTOMFIELD-NAME&order=DESC... Weiterlesen →

Re: How to get posts to list in order, depending on value of custom field :: Reply by adamwork

13. Jun. 2010 (von: adamwork)

Hi masteradmin[/code]Thanks for your response... I've tried updating the code, so it looks like this:Code:<?php if (have_posts()) : ?><?php query_posts('showposts=20&cat=26&orderby=meta_value&meta_key=Price&order=DESC'); $i = 1... Weiterlesen →

Re: How to get posts to list in order, depending on value of custom field :: Reply by adamwork

13. Jun. 2010 (von: adamwork)

RESULT! I changed it to:Code:<?php if (have_posts()) : ?><?php query_posts('showposts=20&cat=26&orderby=meta_value&meta_key=Price&order=ASC'); $i = 1; ?><?php while (have_posts()) : the_post(); ?>    And it w... Weiterlesen →

Autor:

Du findest mich auch auf Google+, Twitter und Facebook!

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.


weitere forum Beiträge: