Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1209107
    edwinyoyo
    Participant

    Hi,

    I have am exact question which have come up a few times. But with a few tweaks.
    https://community.theme.co/forums/topic/church-demo-event-question/
    https://community.theme.co/forums/topic/event-dates-in-church-theme/

    This is not what I am looking for.
    span.x-recent-posts-date {
    display: none !important;
    }

    What I am hoping is to forcefully publish a categorized post that is scheduled in the future. Hence, the date will correspond to the event. In short, I want all posts categorized as “Events” to be published right now even though some of the ones is dated as scheduled/future. I am using the same exact church demo.

    I found this online but I don’t understand the content given I am a beginner.
    http://wordpress.stackexchange.com/questions/175/marking-future-dated-post-as-published

    I attached a screenshot from previous post (exact the same problem). Any help will be very much appreciated.
    The same can apply when you click on the Events Menu on the top right corner of Church demo.

    ed

    #1209331
    Rad
    Moderator

    Hi there,

    Thanks for writing in.

    Your issue isn’t related to those threads, they are about manipulating how the date will be displayed (eg. design and cosmetic related ).

    Your issue is about a query or internal functionality that display posts based on filtered condition. Would you mind providing your site’s URL that has this issue? Demo is just set of contents, it doesn’t do anything than just displaying its page. The functionality remains within the theme core and not on the demo.

    And please provide your login credentials in private reply as well 🙂

    Thanks!

    #1209335
    Lely
    Moderator

    Hello Ed,

    We can use ACF Pro plugin to add custom date field:https://community.theme.co/kb/integrated-plugins-acf-pro/
    Then we will add this custom date field on your recent post shortcode. See attached screenshot.

    Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

    Add the following code on your child theme’s functions.php file:

    // Recent Posts
    // =============================================================================
    
    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'         => ''
      ), $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 );
    
      $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>'
    			   .do_shortcode( '[cs_acf field="event_date"]')
                          // . '<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' );
    }
    

    Above code will work on shortcode only and not on Cornerstone recent post element. Something like this:
    [x_recent_posts type="post" count="4"]

    The changes I made is this lines:

    			   .do_shortcode( '[cs_acf field="event_date"]')
                          // . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
     

    I have commented the default date display and then added the custom field instead.

    Hope this helps.

    #1209378
    edwinyoyo
    Participant
    This reply has been marked as private.
    #1209429
    Christopher
    Moderator

    Hi there,

    Please connect to FTP and find functions.php file under wp-content/theme/x-child.
    Please ask for FTP credentials from your host provider.

    Thanks.

    #1210909
    edwinyoyo
    Participant

    Hi! I found the functions.php. It is in Appearance -> Editor, then on the sidebar. Screenshot attached.

    I included the code block. But then, what’s next?
    Should I add this shortcode somewhere?
    [x_recent_posts type=”post” count=”4″]

    I noticed I can’t add on the homepage because it was edited by Cornerstone. It said it will be overwritten.
    Or should I add it in the post under text?

    One more thing, what does the count represents for the following?
    [x_recent_posts type=”post” count=”4″]

    Thanks again for your help!

    #1211083
    Christopher
    Moderator

    Hi there,

    Switching between editors breaks cornerstone page.
    You can edit home page content in cornerstone, add a text element and insert shrotcode there.

    Count attribute specify number of recent posts which should be displayed. The number could be between 1 to 4. Check this link http://demo.theme.co/integrity-1/shortcodes/recent-posts/

    Hope it helps.

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