Custom search page


Hi everybody,

I set up a custom search page using the various examples already discussed in the forum and looking like this so far:

// Force layout.
add_filter( 'beans_layout', 'example_force_layout' );

function example_force_layout() {

    return 'c';

}

// Modify the search page markup
beans_add_smart_action( 'beans_before_load_document', 'banks_search_setup_document' );
function banks_search_setup_document() {
    // Post
    beans_add_attribute( 'beans_search_title', 'class', 'uk-margin-bottom-remove' );
    beans_add_attribute( 'beans_content', 'class', 'uk-article' );
    beans_remove_attribute( 'beans_post', 'class', 'uk-article' );
    beans_modify_markup( 'beans_post_title', 'h2' );
    beans_add_attribute( 'beans_post_title', 'class', 'uk-h2' );
    beans_add_attribute( 'beans_post', 'class', 'uk-grid-margin' );
    // Post image
    // beans_remove_action( 'beans_post_image' );
    // Post meta
    beans_remove_action( 'beans_post_meta' );
    beans_remove_action( 'beans_post_meta_tags' );
    beans_remove_action( 'beans_post_meta_categories' );
    // Remove article search
    // beans_remove_output( 'beans_no_post_search_form' );
}

add_filter( 'the_content', 'kc_search_view_post_content' );
function kc_search_view_post_content( $content ) {
    return '<p>' . wp_trim_words( wp_strip_all_tags( $content, true ), 55, ' ...' ) . '</p>';
}

// Load beans document.
beans_load_document();

Everything works so far except that I would like to display a little more of the article content than just the headline which is the only thing displayed aside the featured image.

I already tried increasing the number and set 55 to 155 but nothing happened. Did a do something wrong in the setup of the template?

Thanks an advance


Found a solution myself. Here is what did it for me:

add_filter( 'the_content', 'example_view_post_content' );
function example_view_post_content() {
  echo wp_trim_words( get_the_excerpt(), 15, '...' );
}

I use a lot of custom fields within the articles so maybe that was the reason why the content wasn't clearly displayed. I did a workaround using the excerpt instead.

Sorry for my stupid questions but php and wp dev isn't my strongest area.

Write a reply

Login or register to write a reply, it's free!