Search page


Hi Thierry

I'm just trying to create a simple search page with beans. I've created a search.php page with the following code:

<?php

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

function beans_child_force_layout() {

    return 'c';

}

//Wrap for content
beans_add_attribute( 'beans_fixed_wrap[_main]', 'class', 'uk-width-large-2-3 my-padding-large my-side-pad');

?>

<?php

add_action( 'beans_footer_prepend_markup', 'example_footer' );

function example_footer() {

    include("my-foot.php");

}

//Add class to position footer
beans_add_attribute('beans_footer', 'class', 'uk-hidden');

beans_load_document();

This is 'working' but ideally I'd like to be able to customise the returned info. At present I get the post title, the post H1 and the content in full. Plus I get the tags etc. Ideally I'd like no post title, just the h1 and no tags. I'd also like to seperate the result with a hr.

What the best way to approach this 'the beans way'?

Many thanks.



Hey Jason,

As Jochen mentioned, Banks search page is a good example. I think what you are looking for is the following snippet:

// Post.
beans_add_attribute( 'beans_content', 'class', 'uk-panel-box' );
beans_remove_attribute( 'beans_post', 'class', 'uk-panel-box' );
beans_modify_markup( 'beans_post_title', 'h2' );
beans_add_attribute( 'beans_post_title', 'class', 'uk-h2' );

// 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' );

// Truncate content.
add_action( 'the_content', 'example_truncate_content' );

function example_truncate_content( $content ) {

     return '<p>' . wp_trim_words( wp_strip_all_tags( $content, true ), 55, ' ...' ) . '</p>';

}

// Add horizontal dividers.
add_action( 'beans_post_before_markup', 'example_horizontal_divider' );
add_action( 'beans_posts_pagination_before_markup', 'example_horizontal_divider' );

function example_horizontal_divider() {

    ?><hr class="uk-article-divider" /><?php

}

// Load document which is always needed at the bottom of template files.
beans_load_document();

Note that I didn't add your custom footer and layout modification which I will let you add yourself (before the beans_load_document(); line indeed). Regarding the uk-hidden added to the footer, if the intention is to hide/remove remove it, you should rather use beans_remove_action( 'beans_footer_partial_template' ); so that it doesn't load on the page (hiding is not very good practice).

Have fun,


Thanks guys

Yes that's exactly what I needed.

Cheers Jason


Fantastic, I am glad we could help Jason 🙂

Happy coding,

Write a reply

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