Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1200433

    Hi, how can I fix a post in the post-slider module? I use the “keep posts on the home page” option but that doesn’t seem to be taken into account. I have already modified postslider.php in my child theme and would like to include the “Sticky Posts” option. Is this possible?
    Thanks in advance, Melanie

    #1200477

    On one of my enfold playground testpages – i got under each of my single post a post slider with other post to show randomly.
    First: I do not want to show the current post in this post slider on single posts.
    Second: i’d like to have allway that one ( or more ) sticky post on the beginning of that list.

    These codes comes to child-theme functions.php:

    The first is easier to obtain:

    function ava_exclude_current_post($query) {
      if (is_singular('post')) {
        $exclude = avia_get_the_ID();
        $query->set( 'post__not_in', array($exclude) );
      }
    }
    add_action('pre_get_posts', 'ava_exclude_current_post');

    so i exclude the current ID from query.

    The second request:

    add_filter('avia_post_slide_query','avia_order_by_random', 10, 2);
    function avia_order_by_random($query, $params) {
    
    	$include = array();
    	$sticky = get_option( 'sticky_posts' );
    
    	$args = array(
    	'post__not_in' => $sticky,
    	'orderby' => 'rand',   // here you can influence the orderby option of the non sticky post to your needs 
    	);
    	$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;
    }

    orderby: https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters

    if you only want this on special pages you have to work with if-clauses.

    #1200540

    Thank you so much works perfect.
    Sorry another question: is it possible to add a “sticky”-class to the first sticky post?

    Thank you!!
    Melanie

    #1200764

    do you only want to show the latest sticky on that slider first?
    a sticky in sticky does not exist afaik.
    But you have to describe a little better what you want to achieve.

    You can have the newest stickies on top – and you can limit it to a given number.
    rsort( $sticky ); is something could be helpful here – maybe a mod knows a solution

    #1201157

    HI Guenni007,

    your solution works PERFECT for me. It shows the sticky Posts in the Post-Slider on the first position(s). But i miss a class for styling: class=”sticky-post” etc. ;)

    Best wishes, Melanie

    #1202275

    Do you have a link to this page? It is difficult to give concrete advice based only on assumptions.

    Dear Dev. and mods : i see that Enfold uses post_class()
    i like to have the sticky ( or something to have for styling ) class on post_class
    so i did this:

    add_filter( 'post_class', 'add_sticky_classes', 10, 3 ); 
    function add_sticky_classes( $classes, $class, $post_id ) {
        if ( ! is_sticky() ) {
            return $classes;
        }
        global $wp_query;
        $classes[] = 'stickypost-' . $post_id;
        return $classes;
    }

    and on single post now there is that stickypost-ID class
    BUT: on article ( blog pages etc archives ) this CSS class is not forwarded to article allthough it is in postslider.php done.

    #1202312

    ok – you know how to have a custom alb element on your child-theme?
    If not – please tell:

    open postslider.php ( in enfold / config-templatebuilder / avia-shortcodes / postslider )
    open it and look for : $post_class on line 419 : $post_class = "post-entry post-entry-{$the_id} …
    just insert under it:
    if ( is_sticky( $entry->ID ) ) { $post_class .= 'sticky'; }

    so that there is now:

    $post_class = "post-entry post-entry-{$the_id} slide-entry-overview slide-loop-{$post_loop_count} slide-parity-{$parity} {$last}";
    if ( is_sticky( $entry->ID ) ) { $post_class .= 'sticky'; }

    upload that postslider.php to your child-theme shortcodes folder ( on default there is no such folder – then create one)

    to load those edited alb elements instead of the parent one do this to your child-theme functions.php:

    function avia_include_shortcode_template($paths){
      $template_url = get_stylesheet_directory();
          array_unshift($paths, $template_url.'/shortcodes/');
      return $paths;
    }
    add_filter('avia_load_shortcodes', 'avia_include_shortcode_template', 15, 1);

    now all sticky post got this class : sticky on postsliders

    #1203893

    Dear Guenni007,

    thank you this was exactly what i searched for. I put the postslider.php in my childtheme. Everythins works perfect.

    Thanks a lot!
    Melanie

    #1205334

    Hi,
    Glad Guenni007 could help, unless there is anything else we can help with on this issue, shall we close this then?

    Best regards,
    Mike

    #1205757

    My issue is resolved and can be closed ;)

    #1224288

    Hi,
    i used the same solution provided by Guenni007 on April 3, 2020 at 11:45 am but now i can only see the last 6 posts (i have more than 100) and not pagination anymore.

    Am i missing something in the configuration?

    Currently i’m rebuilding the website locally so it’s difficult to provide an example.

    Thanks a million

    #1224291

    Solution found adding “numberposts” to -1 in here:

    $args = array(
    ‘post__not_in’ => $sticky,
    ‘orderby’ => ‘date’,
    ‘numberposts’ => -1
    );

    #1224320

    Hi,
    Glad to hear that you have sorted this out. We will close this then unless you had any further questions for @Guenni007

    Best regards,
    Mike

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