Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1467463

    Hello,
    Advanced Layout Editor -> Content Elements -> Blog Posts -> Blog Style -> Grid Layout.
    “Make post sticky” does not change the order of posts in the grid.
    1. How to stick important posts first in a grid?
    2. How make the order of the posts by date with older posts first?
    Thank you

    #1467511

    Hey ibuzaev,

    Thank you for the inquiry.

    1-2.) To allow sticky posts and adjust the order of the items in the grid layout, please add this filter in the functions.php file:

    add_filter("avia_post_slide_query", function($query, $params) {
        $sticky_posts = get_option('sticky_posts');
        $include = [];
    
        $args = [
            'taxonomy' => $params['taxonomy'],
            'post__not_in' => $sticky_posts,
            'order' => 'ASC',
            'fields' => 'ids',
        ];
        $posts = get_posts($args);
    
        $include = array_merge($sticky_posts, $posts);
        $include = array_map('intval', $include);
    
        $query['post__in'] = $include;
        $query['orderby'] = 'post__in';
        $query['order'] = 'ASC';
    
        return $query;
    }, 10, 2);
    

    Best regards,
    Ismael

    #1467566

    Thank you, Ismael

    #1467567

    Dear Ismael, your function shows only sticky posts now.
    I need to show all posts, sticky first and then date asc.
    Could you please correct the function?

    #1467630

    Hi,

    Thank you for the update.

    Where can we check this? Please provide the site URL and login details in the private field. Make sure that the Appearance > Theme File Editor is accessible.

    Best regards,
    Ismael

    #1467647

    …. it is hard to inspect your page ( i’m not able to read it ;) )

    but if you decide to have alot of sticky posts – and have no pagination on showing the blog – there will be no other posts after the sticky ones.

    My snippet looks a bit different on merging both ( sticky and include) – don’t know if they are equivalent each other:

    function sticky_posts_first($query, $params) {
    
      $include = array();
      $sticky = get_option( 'sticky_posts' );
    
      $args = array(
      'post__not_in' => $sticky,
      'order' => 'ASC', 
      'orderby' => 'date',   // here you can influence the orderby option of the non sticky post to your needs 
      'numberposts' => -1  // if you like to show not only a few 
      );
      $posts = get_posts( $args );
    
      foreach($posts as $post) {
        $include[] = $post->ID;
      }
      if ( !is_sticky() ) {
        $include = array_merge($sticky, $include);
      };
    
      $query['post__in'] = $include;
      $query['orderby'] = 'post__in';
    
    return $query;
    }
    add_filter('avia_post_slide_query','sticky_posts_first', 10, 2);

    maybe you can try that instead

    #1467662

    Thank you Guenni!
    Let me try

    #1467665

    Dear Guenni,
    I used your snippet.
    https://img.savvyify.com/image/Screenshot-2024-09-23-at-12.17.05.9WML8
    Here is a screenshot. So the first three people are sticky (the first row),
    the second row with 4-6 persons are not sticky.
    That is great.
    Now can we sort ASC the sticky too? (there is a date below every photo)
    Sincerely yours,
    Igor

    #1467669

    thats my comment on the page language – where to find that screenshot page?

    if you look to Ismaels code – he placed an order at the end – maybe that will do the job:

    function sticky_posts_first($query, $params) {
    
      $include = array();
      $sticky = get_option( 'sticky_posts' );
    
      $args = array(
      'post__not_in' => $sticky,
      'order' => 'ASC', 
      'orderby' => 'date',   // here you can influence the orderby option of the non sticky post to your needs 
      'numberposts' => -1  // if you like to show not only a few 
      );
      $posts = get_posts( $args );
    
      foreach($posts as $post) {
        $include[] = $post->ID;
      }
      if ( !is_sticky() ) {
        $include = array_merge($sticky, $include);
      };
    
      $query['post__in'] = $include;
      $query['orderby'] = 'post__in';
      $query['order'] = 'ASC';
    
    return $query;
    }
    add_filter('avia_post_slide_query','sticky_posts_first', 10, 2);
    #1467976

    Dear Guenni,

    Thanky you for your help.
    I added this snippet, but it still does not work as expected.

    Sticky posts are first as planned, but they are not ordered.
    The page is here. https://buzaevclinic.ru/team/
    Under the photo there is a date which is language universal.

    I have the same problem with sticky posts in other types of views (list view with exerpt).
    Thank you

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.