0
Welcome Guest! Login
0 items Join Now

Custom Post Order

    • chrisrth's Avatar
    • chrisrth
    • Jr. Rocketeer
    • Posts: 41
    • Thanks: 1

    Custom Post Order

    Posted 11 years 6 months ago
    • Using Gantry 4.0.4, WP 3.5.1
      I have some categories that need to be sorted other than post date.

      1 by random order
      1 by page title
      1 by custom field

      How can I accomplish this per your recommendation?
      I'm not afraid of a little code editing just not sure what system file to tackle this in
    • Shazdeh's Avatar
    • Shazdeh
    • Elite Rocketeer
    • Posts: 4984
    • Thanks: 29

    Re: Custom Post Order

    Posted 11 years 6 months ago
    • Hi,
      you can open up your_theme_root/html/category.php file and then find the line with "new WP_Query" in it: this is where we query for posts. You can modify the parameters sent to that class to modify the query; to change the order you can set the "orderby" parameter (please see here: codex.wordpress.org/Class_Reference/WP_Q...6_Orderby_Parameters ) to sort the posts to your liking.
    • Please don't PM unless requested ;)
      Consider using the custom stylesheet for all your CSS customizations: gantry-framework.org/documentation/wordp...custom_stylesheet.md .
      Please provide the URL to the issue.
      And please mark the thread as solved if the issue is resolved.
    • chrisrth's Avatar
    • chrisrth
    • Jr. Rocketeer
    • Posts: 41
    • Thanks: 1

    Re: Custom Post Order

    Posted 11 years 6 months ago
    • Thanks Shazdeh, did the trick.

      Here's some code, may be of use to someone....
      It would be lovely to have this functionality built-in on a future release.
      I have to believe this is an everyday need for many wordpress admins


      if (is_category('15')) { # Cat 1 RAND

      $custom_query = new WP_Query( array_merge( $query, array( 'orderby' => 'rand', 'posts_per_page' => $gantry->get( $page_type . '-count', '5' ), 'paged' => $paged ) ) );

      } elseif (is_category('16')) { # Cat 2 TITLE ASC

      $custom_query = new WP_Query( array_merge( $query, array( 'orderby' => 'title', 'order'='ASC', 'posts_per_page' => $gantry->get( $page_type . '-count', '5' ), 'paged' => $paged ) ) );

      } elseif (is_category('17')) { # Cat 3 Custom Field DESC

      $custom_query = new WP_Query( array_merge( $query, array( 'orderby' => 'meta_value', 'meta_key'='eventDate', 'order'='DESC', 'posts_per_page' => $gantry->get( $page_type . '-count', '5' ), 'paged' => $paged ) ) );

      } else { # Default

      $custom_query = new WP_Query( array_merge( $query, array( 'posts_per_page' => $gantry->get( $page_type . '-count', '5' ), 'paged' => $paged ) ) );

      }
    • The following users have thanked you: Fundació Cecot Innovació

    • Shazdeh's Avatar
    • Shazdeh
    • Elite Rocketeer
    • Posts: 4984
    • Thanks: 29

    Re: Custom Post Order

    Posted 11 years 6 months ago
    • Hi,
      worth to add that Gantry supports template hierarchy as well, so instead of using conditional comments you can create different template files for each of the categories. In order, Gantry first looks for category-SLUG.php, then category-ID.php and if they didn't exists, category.php file is used.
    • Please don't PM unless requested ;)
      Consider using the custom stylesheet for all your CSS customizations: gantry-framework.org/documentation/wordp...custom_stylesheet.md .
      Please provide the URL to the issue.
      And please mark the thread as solved if the issue is resolved.
    • chrisrth's Avatar
    • chrisrth
    • Jr. Rocketeer
    • Posts: 41
    • Thanks: 1

    Re: Custom Post Order

    Posted 11 years 6 months ago
    • That's great. So I can just copy the contents of category.php to [MYSLUG].php and edit the query as needed for that category only. Gantry will load the custom php file automatically, correct?
    • Shazdeh's Avatar
    • Shazdeh
    • Elite Rocketeer
    • Posts: 4984
    • Thanks: 29

    Re: Custom Post Order

    Posted 11 years 6 months ago
    • Hi,
      yes :) though keep an eye on the naming convention; the filename should be: category-[SLUG].php.
    • Please don't PM unless requested ;)
      Consider using the custom stylesheet for all your CSS customizations: gantry-framework.org/documentation/wordp...custom_stylesheet.md .
      Please provide the URL to the issue.
      And please mark the thread as solved if the issue is resolved.
    • chrisrth's Avatar
    • chrisrth
    • Jr. Rocketeer
    • Posts: 41
    • Thanks: 1

    Re: Custom Post Order

    Posted 11 years 6 months ago
    • I have my custom category pages setup but they do not follow the gantry category rules. i.e. I want to show excerpt and title links, not author or meta data. How can I accomplish this with a custom category page (I just copied the category page, altered the name to include the slug and changed the query)
    • Shazdeh's Avatar
    • Shazdeh
    • Elite Rocketeer
    • Posts: 4984
    • Thanks: 29

    Re: Custom Post Order

    Posted 11 years 6 months ago
    • Hi,
      I think I know what the issue is, can you please try this? Open up that custom category template and find this line:
      $page_type = basename( __FILE__, '.php' );
      and change it into:
      $page_type = 'category';
      It should fix the issue.
    • Please don't PM unless requested ;)
      Consider using the custom stylesheet for all your CSS customizations: gantry-framework.org/documentation/wordp...custom_stylesheet.md .
      Please provide the URL to the issue.
      And please mark the thread as solved if the issue is resolved.
    • chrisrth's Avatar
    • chrisrth
    • Jr. Rocketeer
    • Posts: 41
    • Thanks: 1

    Re: Custom Post Order

    Posted 11 years 6 months ago
    • Awesome, worked.
      Gantry rocks
  • Re: Custom Post Order

    Posted 11 years 5 months ago

Time to create page: 0.052 seconds