- This topic has 10 replies, 3 voices, and was last updated 10 years, 3 months ago by Theme Horse Support Team.
-
AuthorPosts
-
August 11, 2014 at 9:50 pm #12913AmyMember
I am using the “business template” for a home page, with the ThemeHorse services widget displaying quotes and links from four of my pages. Is there a way to change the amount of quoted text from each page? Or a way to control the styling on the quoted text?
I want to show less text from each page. The quote also seems to strip all the formatting off the text.
You can see the page preview here: http://371.f57.myftpupload.com/
Thanks!
-AmyAugust 12, 2014 at 5:31 am #12919Theme Horse Support TeamKeymasterHi Amy,
Yes you can show the less text from each page. Please goto
Dashboard -> Appearance-> Theme – Options -> Advanced Options ->excerpt options.
From here you can define the excerpt length.Thank you!
August 12, 2014 at 6:01 pm #12934AmyMemberGreat, thank you for your help!
August 13, 2014 at 5:19 am #12945Theme Horse Support TeamKeymasterYou welcome Amy
Thank You!August 26, 2014 at 2:05 am #13267DavidMemberHi, Is there a way to change this to be controlled by the number of characters and not the number of words as they still end up with different heights as the words in the excerpts are different lengths. Or perhaps use <more> tags . The excerpts in your preview are all “Lorem Ipsum” and thus come out the same height. With real world text they come out with different lengths and thus heights…
August 26, 2014 at 5:22 am #13270Theme Horse Support TeamKeymasterHi David,
Sorry we don’t have this feature. We only have the excerpt words to define.
Thank you!August 27, 2014 at 1:38 am #13312DavidMemberOk – I took a stab at this myself. Here is what I did if anyone else wants to do this…
first I made a function.php file in my child theme and added the following function
function get_excerpt(){ $excerpt = get_the_content(); $excerpt = preg_replace(" (\[.*?\])",'',$excerpt); $excerpt = strip_shortcodes($excerpt); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, 140); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt)); $excerpt = $excerpt = '<p>'.$excerpt.'... </p>'; return $excerpt; }
On 6th line you can change the 140 to however many characters you like.
Then on line 338 of inc/widgets/interface_widgets.php I changed the code to
<?php get_excerpt(); ?>
I tried making a copy of the file with the changes in my child theme but it won’t override the parent theme – therefore this change will be lost upon updating. Anyone got any thoughts on how to accomplish this without losing the changes on the next update?
August 27, 2014 at 3:52 am #13314DavidMemberOops , the post above should read functions.php – just to avoid confusion
August 27, 2014 at 5:10 am #13315Theme Horse Support TeamKeymasterHi David,
In functions.php of the child theme, create your widgets and register them. Just copy the parent widget, change the name of widget like Theme Horse Child: Featured Page Widget, make customisation and create your custom widget. If you do this, the widgets of parent theme and child both will appear. Use your custom widget of child theme instead of the parent theme.
Just making same file structure in the child theme like /library/widgets won’t overwrite the parent file. Hope this helps.
Thank you!
August 28, 2014 at 12:32 am #13337DavidMemberThank You! That works beautifully. I posted a mistake above where it says
<?php get_excerpt(); ?>
it should read
<?php echo get_excerpt(); ?>
Here is the code in my functions.php in it’s entirety.<?php /** *Function that trims excerpt by number of characters and ensures that the last word doesn't get cut off */ function get_excerpt(){ $excerpt = get_the_content(); $excerpt = preg_replace(" (\[.*?\])",'',$excerpt); $excerpt = strip_shortcodes($excerpt); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, 360); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt)); $excerpt = $excerpt = '<p>'.$excerpt.'... </p>'; return $excerpt; } /** * Widget for business layout that shows selected page content,title and featured image. Uses function above to control excerpt length by number of characters and not words * Construct the widget. * i.e. Name, description and control options. */ class interface_child_service_widget extends WP_Widget { function interface_child_service_widget() { $widget_ops = array( 'classname' => 'widget_service', 'description' => __( 'Display Services by no.of chars( Business Layout )', 'interface' ) ); $control_ops = array( 'width' => 200, 'height' =>250 ); parent::WP_Widget( false, $name = __( 'Theme Horse: Services Custom', 'interface' ), $widget_ops, $control_ops); } function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'number' => '8','page_id0'=>'','page_id1'=>'','page_id2'=>'','page_id3'=>'','page_id4'=>'','page_id5'=>'','page_id6'=>'','page_id7'=>'',)); $number = absint( $instance[ 'number' ] ); for ( $i=0; $i<$number; $i++ ) { $var = 'page_id'.$i; $defaults[$var] = ''; } ?> <p> <label for="<?php echo $this->get_field_id('number'); ?>"> <?php _e( 'Number of Services:', 'interface' ); ?> </label> <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /> </p> <?php for ( $i=0; $i<$number; $i++ ) { $var = 'page_id'.$i; $var = absint( $instance[ $var ] ); } ?> <?php for( $i=0; $i<$number; $i++) { ?> <p> <label for="<?php echo $this->get_field_id( key($defaults) ); ?>"> <?php _e( 'Page', 'interface' ); ?> :</label> <?php wp_dropdown_pages( array( 'show_option_none' =>' ','name' => $this->get_field_name( key($defaults) ), 'selected' => $instance[key($defaults)] ) ); ?> </p> <?php next( $defaults );// forwards the key of $defaults array } } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['number'] = absint( $new_instance['number'] ); for( $i=0; $i<$instance['number']; $i++ ) { $var = 'page_id'.$i; $instance[ $var] = absint( $new_instance[ $var ] ); } return $instance; } function widget( $args, $instance ) { extract( $args ); extract( $instance ); $number = empty( $instance['number'] ) ? 8 : $instance['number']; global $post; global $interface_theme_setting_value; $options = $interface_theme_setting_value; $page_array = array(); for( $i=0; $i<$number ; $i++ ) { $var = 'page_id'.$i; $page_id = isset( $instance[ $var ] ) ? $instance[ $var ] : ''; if( !empty( $page_id ) ) array_push( $page_array, $page_id );// Push the page id in the array } $get_featured_pages = new WP_Query( array( 'posts_per_page' => -1, 'post_type' => array( 'page' ), 'post__in' => $page_array, 'orderby' => 'post__in' ) ); echo $before_widget; ?> <div class="column clearfix"> <?php $j = 1; while( $get_featured_pages->have_posts() ):$get_featured_pages->the_post(); $page_title = get_the_title(); if( $j % 4 == 3 && $j > 1 ) { $service_class = "one-fourth clearfix-half"; } elseif ( $j % 4 == 1 && $j > 1 ) { $service_class = "one-fourth clearfix-half clearfix-fourth"; } else { $service_class = "one-fourth"; } ?> <div class="<?php echo $service_class; ?>"> <div class="service-item clearfix"> <?php if ( has_post_thumbnail() ) { echo'<div class="service-icon">'.get_the_post_thumbnail( $post->ID, 'icon' ).'</div>'; } ?> <h3 class="service-title"><?php echo $page_title; ?></h3> </div> <!-- .service-item --> <article> <?php echo get_excerpt(); ?> </article> <?php if( !empty( $options[ 'post_excerpt_more_text' ] ) ) { ?> <a class="more-link" title="<?php the_title_attribute(); ?>" href="<?php the_permalink(); ?>"> <?php echo $options[ 'post_excerpt_more_text' ]; ?></a> <?php } ?> </div> <!-- .one-fourth --> <?php $j++; ?> <?php endwhile; // Reset Post Data wp_reset_query(); ?> </div> <!-- .column --> <?php echo $after_widget; } } function myplugin_register_widgets() { register_widget( 'interface_child_service_widget' ); } add_action( 'widgets_init', 'myplugin_register_widgets' ); /**************************************************************************************/ ?>
August 28, 2014 at 4:50 am #13340Theme Horse Support TeamKeymasterOk that’s great David,
Thank you! -
AuthorPosts
- You must be logged in to reply to this topic.