Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1266701
    wal v
    Participant

    Hi X,

    I keep using this theme it’s great 😀
    But i have a question, i already tried to find a solution at this forum but couldnt find any.
    on my blog page, http://www.naber-vastgoedbeheer.nl/vastgoed-actueel-2/
    I made a page with recent posts, so i could have a intro text above the posts.
    But it’s limited to only 4 posts, is it possible to have some more, (unlimited)?

    Hopefully you can help me out!
    Thanks for your time!

    #1266707
    Darshana
    Moderator

    Hi there,

    Thanks for writing in! You can use Recent Posts shortcode with the offset parameter.

    For example, to display the first 4 posts.
    [recent_posts count="4" orientation="horizontal"]

    To display the next 4 posts:
    [recent_posts count="4" orientation="horizontal" offset="4"]

    For more information, please refer (http://demo.theme.co/integrity-1/shortcodes/recent-posts/).

    Hope that helps.

    #1268033
    wal v
    Participant

    Hi X,

    Thanks for your reply, but this way i can only show 4 reent posts, is there no way i can show all my posts?

    #1268084
    Paul R
    Moderator

    Hi,

    To display all posts, add this in your child theme’s funcitons.php file.

    
    function x_shortcode_recent_posts_v2code( $atts ) {
      extract( shortcode_atts( array(
        'id'           => '',
        'class'        => '',
        'style'        => '',
        'type'         => 'post',
        'count'        => '',
        'category'     => '',
        'offset'       => '',
        'orientation'  => '',
        // 'show_excerpt' => 'true',
        'no_sticky'    => '',
        'no_image'     => '',
        'fade'         => '',
        'all_posts'    => ''
      ), $atts, 'x_recent_posts' ) );
    
      $allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post' ) );
      $type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post';
    
      $id            = ( $id           != ''     ) ? 'id="' . esc_attr( $id ) . '"' : '';
      $class         = ( $class        != ''     ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
      $style         = ( $style        != ''     ) ? 'style="' . $style . '"' : '';
      $count         = ( $count        != ''     ) ? $count : 3;
      $category      = ( $category     != ''     ) ? $category : '';
      $category_type = ( $type         == 'post' ) ? 'category_name' : 'portfolio-category';
      $offset        = ( $offset       != ''     ) ? $offset : 0;
      $orientation   = ( $orientation  != ''     ) ? ' ' . $orientation : ' horizontal';
      // $show_excerpt  = ( $show_excerpt == 'true' );
      $no_sticky     = ( $no_sticky    == 'true' );
      $no_image      = ( $no_image     == 'true' ) ? $no_image : '';
      $fade          = ( $fade         == 'true' ) ? $fade : 'false';
    
      $js_params = array(
        'fade' => ( $fade == 'true' )
      );
    
      $data = cs_generate_data_attributes( 'recent_posts', $js_params );
    
      if ( $all_posts == 'true' ) {
        $count = -1;
        $class .= ' all_posts';
      }
      
      $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";
    
        $q = new WP_Query( array(
          'orderby'             => 'date',
          'post_type'           => "{$type}",
          'posts_per_page'      => "{$count}",
          'offset'              => "{$offset}",
          "{$category_type}"    => "{$category}",
          'ignore_sticky_posts' => $no_sticky
        ) );
    
        if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
    
          if ( $no_image == 'true' ) {
            $image_output       = '';
            $image_output_class = 'no-image';
          } else {
            $image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'entry-cropped' );
            $bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
            $image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
            $image_output_class = 'with-image';
          }
    
          // $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p>' . preg_replace('/<a.*?more-link.*?<\/a>/', '', cs_get_raw_excerpt() ) . '</p></div>' : '';
    
          $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', 'cornerstone' ), the_title_attribute( 'echo=0' ) ) ) . '">'
                     . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
                       . '<div class="entry-wrap">'
                         . $image_output
                         . '<div class="x-recent-posts-content">'
                           . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
                           . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
                           // . $excerpt
                         . '</div>'
                       . '</div>'
                     . '</article>'
                   . '</a>';
    
        endwhile; endif; wp_reset_postdata();
    
      $output .= '</div>';
    
      return $output;
    }
    
    add_action('wp_head', 'change_recent_posts_to_v2');
    function change_recent_posts_to_v2() {
      remove_shortcode( 'x_recent_posts' );
      add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v2code' );
    }
    

    Then add this in Custom > Edit Global CSS in the customizer.

    
    .x-recent-posts.all_posts a {
        float:none;
        display:inline-block;
        width:22%;
        margin:0 1.5%;
    }
    
    .x-recent-posts.all_posts {
       text-align:center;
    }
    

    After that, you will need to use the recent posts shortcode to display all your post.

    eg.

    
    [x_recent_posts all_posts="true" ]
    

    Hope that helps.

    #1268200
    wal v
    Participant

    Hi X,

    Thanks for your time!
    But the code you gave me didnt do the trick, i still only see 4 posts and they show a image.
    I need all posts without image.

    Thanks!

    #1268302
    Nabeel A
    Moderator

    Hi again,

    I tested the above code locally and it works fine on my end. Please make sure you’re using the following shortcode:

    [x_recent_posts all_posts="true" no_image="true"]

    If this doesn’t work then provide us with FTP credentials in a private reply so we can take a closer look.

    Thanks!

    #1284430
    wal v
    Participant

    Thanks X
    This worked!

    #1284446
    Paul R
    Moderator

    You’re welcome! 🙂

  • <script> jQuery(function($){ $("#no-reply-1266701 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>