Regarding showing post data in Recent Post

Hi,

We want to show post meta such as below with recent post shortcode

  • Post’s Title

  • Feature Image

  • Excerpt

  • Post’s Author

  • Post’s Date

  • Post’s categories

  • Post’s Tags

But we can not find the solution. Hoping for the solution. Also we have revolution slider with the latest post at Home Page.

Thank You and Best regards

Hi @worxpronext,

Please setup a child theme first:

Then take a look at this article https://theme.co/apex/forum/t/meta-and-excerpt-on-the-recent-post-short-code/32447/2?u=thai

Hope it helps :slight_smile:

Hi,

Thank you for reply. But we don’t see post categories and tags with this code. We have used child theme.

We want author to be linked at author page, date to date archive page, categories at categories archive page and so on. Also we want to have read more link to detail post at the bottom of post.

Hoping for your support in this regards.

Thank You and best regards.

Hi @worxpronext,

What you are trying to achieve requires custom code which is outside the scope of support that we offer.
The code provided serves only as a guide and it was provided to give users something to start with.

You can add the codes for categories, tags and author link to the code provided.
For reference, kindly check the links below

https://developer.wordpress.org/reference/functions/get_categories/
https://developer.wordpress.org/reference/functions/get_the_tags/
https://codex.wordpress.org/Function_Reference/get_the_author_link

Thank you for understanding

Hi,

Sorry but the link https://developer.wordpress.org/reference/functions/get_the_tags/
produce “Array” as output with the code provided above.

Also the link “https://codex.wordpress.org/Function_Reference/get_the_author_link” produced Author Name but not Author Name along with the link.

Hoping support in this regards.

Thank you and best regards.

Hi @worxpronext,

Please note that those are just guides and will not exactly produce what you needed.

get_the_author_link will produce the author’s name linked to the author’s page

For the tags, you will need to code it so it doesn’t display an array

https://php.net/manual/en/function.implode.php

As stated from my previous reply, this requires custom development, if you are not comfortable with HTML and PHP, you need to hire a web developer to do this for you.

Thank you for understanding.

Hi,

Thank you for your links and Kind support.

Thank you and best regards.

Hi,

Can you please let me know the name of PHP file and location of file that delivers recent posts in theme.

Thank you and best regards.

Hi @worxpronext,

You don’t have to copy that file to the child theme. Just need to paste the custom PHP code under functions.php file locates in your child theme. Same as this ticket:

Hope it helps :slight_smile:

Hi,

Thank you for reply. We have already used this code in our child theme. Furthermore, we also want to show tags in our recent post as it shows author and excerpt.

Thank you and best regards.

Hello @worxpronext,

Since you are already using the recent posts element code in your child theme, you will have to modify the code again if you want to show tags, authors and excerpts in the recent posts element.

By the way, if you want to modify your blog index or archive pages to display the excerpts, tags, authors and other post metadata just like in this demo (http://demo.theme.co/integrity-2/blog/), then there is no need for special code since everything is already in the theme. All you have to do is to enable it in X > Theme Options > Blog.

Hope this helps.

Hi,

Thank you for reply.

We want to show above feature (excerpts, tags, authors and post meta) with the Recent Post feature that is available via Recent Post’s element at cornerstone.

Thank you and best regards.

Hey @worxpronext,

As i’ve mentioned in my previous reply, adding the tags in the recent posts element will require you to modify the current code that you already have in your child theme. Please understand that this particular customization request is outside the scope of our support as this is not related to an issue with the theme and instead has to do with your customization of it. As such, you will need to investigate this particular issue on your own or seek help from a developer should you not feel comfortable making these changes yourself. If you have any further questions about the theme, we are more than happy to provide you with assistance on these inquiries.

Please note that custom coding is outside the scope of our support. Issues that might arise from the use of custom code and further enhancements should be directed to a third party developer.

Thank you for your understanding.

Hi,

Thank you for reply. We understand it. Thanks once for support.

In mean time it would be great if you can please let us know the name of PHP file and location of file in theme that delivers recent posts. We will customize it.

Thank you and best regards.

Hello @worxpronext,

This is the original code of the recent post element.

<?php

// Recent Posts
// =============================================================================

function x_shortcode_recent_posts( $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 );

  $posts = get_posts( array(
    'orderby'             => 'date',
    'post_type'           => "{$type}",
    'posts_per_page'      => "{$count}",
    'offset'              => "{$offset}",
    "{$category_type}"    => "{$category}",
    'ignore_sticky_posts' => $no_sticky
  ) );

  $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";

    foreach ($posts as $post) {

      if ( $no_image == 'true' ) {
        $image_output       = '';
        $image_output_class = 'no-image';
      } else {
        $image              = wp_get_attachment_image_src( get_post_thumbnail_id( $post->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';
      }

      $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( csi18n('shortcodes.recent-posts-permalink'), the_title_attribute( array( 'echo' => false, 'post' => $post->ID ) ) ) ) . '">'
                 . '<article id="post-' . $post->ID . '" class="' . implode( ' ', get_post_class('', $post->ID) ) . '">'
                   . '<div class="entry-wrap">'
                     . $image_output
                     . '<div class="x-recent-posts-content">'
                       . '<h3 class="h-recent-posts">' . get_the_title( $post->ID ) . '</h3>'
                       . '<span class="x-recent-posts-date">' . get_the_date( '', $post->ID ) . '</span>'
                     . '</div>'
                   . '</div>'
                 . '</article>'
               . '</a>';

    }

  $output .= '</div>';

  return $output;
}

add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts' );

This code can be found in wp-content/plugins/cornerstone/includes/shortcodes/recent-posts.php. We DO NOT recommend modifying the codes directly on this file because when there is a Cornerstone plugin update, all your modifications will be wipe out. The correct of modifying this code is by adding this code in your chid theme’s functions.php file. This would override the recent posts element shortcode and will always be safe when there is a plugin update.

Hope this helps.

Hi,

Thank you for the code and file location. We will sure update file in child theme.

Thank you and best regards.

You’re welcome!
We’re glad we were able to help you out.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.