Blog-post on Landing Page in Pro

In this post I asked about news items on a landing page. The given code works for X, but not for Pro.
How can I adjust the code so that it is displayed properly.
Old question in X

Hello @madref,

Thanks for writing in! The code given in the other thread should work for X and Pro theme. I cannot check your site though because the given credentials is not working. It seems that the username was incorrect.

Check the access again so we can log in and investigate.

Thanks.

Forgot something in the ur. Now it should work

Hello @madref,

I was able to log in. I still could not check it because editing the child theme files were not allowed. Can you please post the contents of your child theme’s functions.php file instead?

And by the way, I edited the homepage and I can see that you are using the classic recent posts element which works the same way as the recent posts shortcode. When editing in Pro Editor, it is recommended to use the classic recent posts element instead of the shortcode.

Thank you.

The is the code in Functions.php.

[code]<?php

// =============================================================================
// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to Pro in this file.
// =============================================================================

// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
// 01. Enqueue Parent Stylesheet
// 02. Additional Functions
// =============================================================================

// Enqueue Parent Stylesheet
// =============================================================================

add_filter( ‘x_enqueue_parent_stylesheet’, ‘__return_true’ );

// Additional Functions
// =============================================================================

// Entry Meta
// =============================================================================

if ( ! function_exists( ‘x_icon_entry_meta’ ) ) :
function x_icon_entry_meta() {

//
// Author.
//

$author = sprintf( '<span style="color:#FF2A13"><i class="x-icon-pencil" data-x-icon="&#xf2c3"></i> %s</span>',
  get_the_author()
);

//
// Date.
//


$date = sprintf( '<span style="color:#FF2A13"><time class="entry-date" datetime="%1$s"><i class="x-icon-calendar" data-x-icon="&#xf274;"></i> %2$s</time></span>',
  esc_attr( get_the_date( 'c' ) ),
  esc_html( get_the_date() )
);

//
// Output.
//

if ( x_does_not_need_entry_meta() ) {
  return;
} else {
  printf( '<p class="p-meta">%2$s</p>',
    $author,
    $date,
	$comments
  );
}

}
endif;

// =============================================================================
// My Entry Meta
// =============================================================================

if ( ! function_exists( ‘x_icon_my_entry_meta’ ) ) :
function x_icon_my_entry_meta() {

//
// Categories.
//

if ( get_post_type() == 'x-portfolio' ) {
  if ( has_term( '', 'portfolio-category', NULL ) ) {
    $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
    $separator         = ', ';
    $categories_output = '';
    foreach ( $categories as $category ) {
      $categories_output .= '<a href="'
                          . get_term_link( $category->slug, 'portfolio-category' )
                          . '" title="'
                          . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                          . '"><i class="x-icon-bookmark" data-x-icon=""></i> '
                          . $category->name
                          . '</a>'
                          . $separator;
    }

    $categories_list = sprintf( '<span>%s</span>',
      trim( $categories_output, $separator )
    );
  } else {
    $categories_list = '';
  }
} else {
  $categories        = get_the_category();
  $separator         = ', ';
  $categories_output = '';
  foreach ( $categories as $category ) {
    $categories_output .= '<a href="'
                        . get_category_link( $category->term_id )
                        . '" title="'
                        . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                        . '"><i class="x-icon-bookmark" data-x-icon=""></i> '
                        . $category->name
                        . '</a>'
                        . $separator;
  }

  $categories_list = sprintf( ' Categorieën : <span>%s</span>',
    trim( $categories_output, $separator )
  );
}

//
// Output.
//

if ( x_does_not_need_entry_meta() ) {
  return;
} else {
  printf( '<span class="entry-content content"><i class="x-icon-tags" data-x-icon="&#xf07c;"></i>%1$s%2$s</span>',
    $categories_list,
    $comments
  );
}

}
endif;

add_action(‘x_after_view_global__content’, ‘add_post_tags’);
function add_post_tags() {
if( is_singular(‘post’) ) {
if ( has_tag() ) : ?>



<?php x_icon_my_entry_meta(); ?>
<?php echo get_the_tag_list( '
Tags  :  ', ', ', '' ); ?>

<?php endif; } } add_action('x_before_view_global__index', 'icon_archive_title'); function icon_archive_title () { if( is_category() ) : ?> <?php $title = ( $meta['archive-title'] != '' ) ? $meta['archive-title'] : single_cat_title("", false); ?>

<?php echo $title ?>

<?php echo category_description(); ?> <?php endif; }

// FIX DROPCAPPED LETTER NOT SHOWING IN EXCERPTS
function custom_excerpt($text = ‘’) {
$raw_excerpt = $text;
if ( ‘’ == $text ) {
$text = get_the_content(’’);
// $text = strip_shortcodes( $text );
$text = do_shortcode( $text );
$text = apply_filters(‘the_content’, $text);
$text = str_replace(’]]>’, ‘]]>’, $text);
$excerpt_length = apply_filters(‘excerpt_length’, 55);
$excerpt_more = apply_filters(‘excerpt_more’, ’ ’ . ‘[…]’);
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
return apply_filters(‘wp_trim_excerpt’, $text, $raw_excerpt);
}

remove_filter( ‘get_the_excerpt’, ‘wp_trim_excerpt’ );
add_filter( ‘get_the_excerpt’, ‘custom_excerpt’ );

add_action( ‘wp_head’, ‘print_fa_font’ );
function print_fa_font(){
?>

<?php }

// Displaying Excerpt in Recent Posts
// =============================================================================

function x_shortcode_recent_posts_v2( $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( csi18n('shortcodes.recent-posts-permalink'), 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">'
                   . '<h2 class="h-recent-posts">' . get_the_title() . '</h2>'
                   . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
                    . $excerpt
                 . '</div>'
               . '</div>'
             . '</article>'
           . '</a>';

endwhile; endif; wp_reset_postdata();

$output .= ‘’;

return $output;

}

add_filter(‘wp_head’, ‘custom_recent_posts’);

function custom_recent_posts() {
remove_shortcode( ‘x_recent_posts’ );
remove_shortcode( ‘recent_posts’ );
add_shortcode( ‘x_recent_posts’, ‘x_shortcode_recent_posts_v2’ );
add_shortcode( ‘recent_posts’, ‘x_shortcode_recent_posts_v2’ );
}[/code]

Hi @madref,

The code and your entire functions.php file works just fine, I’ve tested it on my dev site, I see that you have an x-child theme as well, is there a chance that you accidentally added the code in the x-child instead of the pro-child?

These are my recent posts element with your very own functions.php file

If the issue persists, please do testing for a plugin conflict. You can do this by deactivating all third party plugins, and seeing if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

Cheers!

no it’s in the right sot

I think that the problem was that it wasn’t uploaded correctly.
Once i uploaded it correctly it all worked.

Thanx for the help

Hey @madref,

You’re welcome! It’s good to know that your issue was now resolved.
If you need anything else we can help you with, don’t hesitate to open another thread.

Best Regards.

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