Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1249854
    Jan Hoogland
    Participant

    Hi,

    I’am looking for a solution to add custom meta information to the portfolio-items displayed on a recents posts section, portfolio-items on the portfolio-page and the single portfolio-item page. I saw a thread about this particulair subject and my question is where do I have to put the code?

    This is the answer one of the staff-members of Themeco gave:

    — begin

    Hi Tim,

    It should be on the editor screen. It’s possible that the visibility is toggled off. You can switch that on from “Screen Options” in the top right.

    To get a single custom field value, this code should work for you:

    $value = get_post_meta( get_the_ID(), ‘name_of_custom_field’, true );

    Let us know how it goes! Take care!
    — end

    This is for a site I build for a client, which is in the desing-fase, so I can’t provide a url or screenshot.

    Thanks,
    Jan

    #1249965
    Paul R
    Moderator

    Hi Jan,

    You can add it in content-portfolio.php

    Kindly copy the file – wp-content/themes/x/framework/views/{STACK}/content-portfolio.php
    to your child theme – wp-content/themes/x-child/framework/views/{STACK}/content-portfolio.php

    Then add the code to the file that is in your child theme.

    Can you provide us the link to that thread.

    Thanks

    #1249973
    Jan Hoogland
    Participant
    #1250201
    Darshana
    Moderator

    Hi there,

    You can utilize the Advanced Custom Fields Pro plugin that now comes bundled with X and follow the template integration instruction at (https://community.theme.co/kb/integrated-plugins-acf-pro/)

    To check a similar example, refer to the following post so that you can get an idea (https://community.theme.co/forums/topic/portfolio-featured-image-renew/#post-1108924).

    Hope that helps.

    #1250219
    Jan Hoogland
    Participant
    This reply has been marked as private.
    #1250778
    Rue Nel
    Moderator

    Hello There,

    Thanks for the updates! Yes you can possibly do this layout with the help of ACF and custom coding. As this is all custom development, regretfully we won’t be able to assist further. Basically our support covers getting setup, theme features, and bug fixes. Custom development is outside the scope of our support. We’re happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation.

    Thank you for your understanding.

    #1265833
    Jan Hoogland
    Participant

    Hello,

    I’am busy building the website I mentioned before. I have made a custom field with ACF Pro, but now I’am looking for the right location I have to place the php code which make sure the custom field is displayed on the ‘recent posts portfolio items’. Do U know which file to use from my childtheme? I use Integrity.

    Thanks!

    Jan

    #1266020
    Darshana
    Moderator

    Hi there,

    Check the following file content-portfolio.php located under (“x/framework/views/integrity/content-portfolio.php”).

    Then you can locate the content below the following line of code.
    <?php if ( x_is_portfolio_item() ) : ?>

    Hope that helps.

    #1266460
    Jan Hoogland
    Participant

    Hello,

    That worked! But it only visible on the single-portfolio-item page. Now I want to display the custom field also in the recent-posts output for the portfolio-items, as well on the portfolio page layout with all the portfolio-items. Can U tell me which file to use?

    Thanks!

    Jan

    #1266470
    Jan Hoogland
    Participant

    I already tried a solution from your forum. Unfortunally it didn’t work for me. But is the solution in functions.php?

    Thanks!

    Jan

    #1266541
    Lely
    Moderator

    Hello Jan,

    Yes, the solution would be to add the following on your child theme’s functions.php

    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>'
                           . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
                           // . $excerpt
       		      .do_shortcode( '[cs_acf field="customfieldname"]')
                         . '</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 look for this line of code:
    .do_shortcode( '[cs_acf field="customfieldname"]')
    Change customfieldname to your own custom field name.

    Hope this helps.

    #1266666
    Jan Hoogland
    Participant

    That worked! Thanks!

    Is it possible to combine two functions in functions.php. In another forum-item which I’ve started, you guys gave me a solution for displaying the category beneath the recents posts portfolio item, also in functions.php.

    Can U tell me how I can combine these two adjustments?

    https://community.theme.co/forums/topic/display-categories-portfolio-item-in-recent-posts-section/

    Thanks!

    Jan

    #1266679
    Christopher
    Moderator

    Hi there,

    please update your code to :

    function x_shortcode_recent_posts_v2( $atts ) {
      extract( shortcode_atts( array(
        'id'          => '',
        'class'       => '',
        'style'       => '',
        'type'        => 'post',
        'count'       => '',
        'category'    => '',
        'offset'      => '',
        'orientation' => '',
        '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';
      $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}"
        ) );
    
        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';
          }
    	  if($type =='post'){
    		$display_for_post = get_the_date();
    		}else{
    		$categories = get_the_terms( get_the_ID() , 'portfolio-category' );		
    		$display_for_post = $categories[0]->name;
    		}
    
          $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', csl18n() ), 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" style="text-align: center;">' . get_the_title() . '</h3>'
    					   . '<div class="meta-wrapper">'
                           . 	'<span class="x-recent-posts-date" style="text-align: center;">' . $display_for_post. '</span>'
                           .do_shortcode( '[cs_acf field="customfieldname"]')
    					   . '</div>'
    
                         . '</div>'
                       . '</div>'
                     . '</article>'
                   . '</a>';
    
        endwhile; endif; wp_reset_postdata();
    
      $output .= '</div>';
    
      return $output;
    }
    
    add_filter('wp_head', 'custom_recent_posts');
    
    function custom_recent_posts() {
      remove_shortcode( 'x_recent_posts' );
    
      add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v2' );
    }

    Hope it helps.

    #1266705
    Jan Hoogland
    Participant

    Marvelous!

    Thanks!

    #1266712
    Darshana
    Moderator

    Glad we were able to help 🙂

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