Remove Woocommerce standard wrapper <div class="woocommerce columns-''> - php

I use custom theme with woocommerce. My main page displays products by categories and they are wrapped in the standard woocommerce block <div class="woocommerce columns-4">. I need to remove it. In woocommerce folder i found just a single reference about this block in woocommerce/includes/class-wc-shortcodes.php
return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
I tried to change it to return '';, but still have the same wrapper.
Is there any option to remove this block?
Function with <div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>' is below.
public static function product_categories( $atts ) { public static function product_categories( $atts ) {
global $woocommerce_loop;
if ( isset( $atts['number'] ) ) {
$atts['limit'] = $atts['number'];
}
$atts = shortcode_atts( array(
'limit' => '-1',
'orderby' => 'name',
'order' => 'ASC',
'columns' => '4',
'hide_empty' => 1,
'parent' => '',
'ids' => '',
), $atts, 'product_categories' );
$ids = array_filter( array_map( 'trim', explode( ',', $atts['ids'] ) ) );
$hide_empty = ( true === $atts['hide_empty'] || 'true' === $atts['hide_empty'] || 1 === $atts['hide_empty'] || '1' === $atts['hide_empty'] ) ? 1 : 0;
// Get terms and workaround WP bug with parents/pad counts.
$args = array(
'orderby' => $atts['orderby'],
'order' => $atts['order'],
'hide_empty' => $hide_empty,
'include' => $ids,
'pad_counts' => true,
'child_of' => $atts['parent'],
);
$product_categories = get_terms( 'product_cat', $args );
if ( '' !== $atts['parent'] ) {
$product_categories = wp_list_filter( $product_categories, array(
'parent' => $atts['parent'],
) );
}
if ( $hide_empty ) {
foreach ( $product_categories as $key => $category ) {
if ( 0 === $category->count ) {
unset( $product_categories[ $key ] );
}
}
}
$atts['limit'] = '-1' === $atts['limit'] ? null : intval( $atts['limit'] );
if ( $atts['limit'] ) {
$product_categories = array_slice( $product_categories, 0, $atts['limit'] );
}
$columns = absint( $atts['columns'] );
$woocommerce_loop['columns'] = $columns;
ob_start();
if ( $product_categories ) {
woocommerce_product_loop_start();
foreach ( $product_categories as $category ) {
wc_get_template( 'content-product_cat.php', array(
'category' => $category,
) );
}
woocommerce_product_loop_end();
}
woocommerce_reset_loop();
return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
}

if you removed woocommerce from the class many of your site's woocommerce functionality may crash.
its not recommended if you want to add custom-class just use jquery.addclass
$('#yourid').addClass('class-to-be-added');
$('#yourid').removeClass('class-to-be-removed');

You can use following jQuery code:
<script>
jQuery( document ).ready(function() {
var proUL = jQuery( ".products" );
if ( proUL.parent().is( "div" ) ) {
jQuery( ".products" ).unwrap();
}
});
</script>

Related

Add array attributes to implode()

I don't know PHP, but I have to work in it. I need add to $attr['ids'] array with $gallery_setting.
function the_featured_image_gallery( $atts = array() ) {
$gallery_setting = get_theme_mod( 'featured_image_gallery' );
if ( is_array( $gallery_setting ) && ! empty( $gallery_setting ) ) {
$atts['ids'] = implode( ',', $gallery_setting );
echo gallery_shortcode( $atts );
}
}
Ideally, I would like:
echo gallery_shortcode( $atts, array(
'order' => 'ASC',
'size' => 'full',
'link' => 'none'
) );
but I know that it does not work.
Please clarify your question. It's not clear what your problem is...
To try a shot in the dark:
function the_featured_image_gallery( $atts = array() ) {
$gallery_setting = get_theme_mod( 'featured_image_gallery' );
if ( is_array( $gallery_setting ) && ! empty( $gallery_setting ) ) {
$atts['ids'] = implode( ',', $gallery_setting );
$additional_atts = array(
'order' => 'ASC',
'size' => 'full',
'link' => 'none'
);
$atts = array_merge($atts, $additional_atts);
echo gallery_shortcode( $atts );
}
}

Make dropdown menu with subcategories using php

I want to change a given menu with submenus into a dropdown menu.
Actually it opens a new row below the main menu. You can see in the given screenshot here.
I have searched in the code for the shown css class nm-shop-sub-categories and found this function. The class nm-shop-sub-categories is at the end of the function.
/*
* Product category menu: Output
*/
if ( ! function_exists( 'nm_category_menu_output' ) ) {
function nm_category_menu_output( $is_category, $current_cat_id, $hide_empty ) {
global $wp_query, $nm_theme_options;
$page_id = wc_get_page_id( 'shop' );
$page_url = get_permalink( $page_id );
$hide_sub = true;
$current_top_cat_id = null;
$all_categories_class = '';
// Is this a category page?
if ( $is_category ) {
$hide_sub = false;
// Get current category's top-parent id
$current_cat_parents = get_ancestors( $current_cat_id, 'product_cat' );
if ( ! empty( $current_cat_parents ) ) {
$current_top_cat_id = end( $current_cat_parents ); // Get last item from array
}
// Get current category's direct children
$current_cat_direct_children = get_terms( 'product_cat',
array(
'fields' => 'ids',
'parent' => $current_cat_id,
'hierarchical' => true,
'hide_empty' => $hide_empty
)
);
$category_has_children = ( empty( $current_cat_direct_children ) ) ? false : true;
} else {
// No current category, set "All" as current (if not product tag archive or search)
if ( ! is_product_tag() && ! isset( $_REQUEST['s'] ) ) {
$all_categories_class = ' class="current-cat"';
}
}
$output_cat = '<li' . $all_categories_class . '>' . esc_html__( 'All', 'nm-framework' ) . '</li>';
$output_sub_cat = '';
$output_current_sub_cat = '';
// Categories order
$orderby = 'slug';
$order = 'asc';
if ( isset( $nm_theme_options['shop_categories_orderby'] ) ) {
$orderby = $nm_theme_options['shop_categories_orderby'];
$order = $nm_theme_options['shop_categories_order'];
}
$categories = get_categories( array(
'type' => 'post',
'orderby' => $orderby, // Note: 'name' sorts by product category "menu/sort order"
'order' => $order,
'hide_empty' => $hide_empty,
'hierarchical' => 1,
'taxonomy' => 'product_cat'
) );
// Categories menu divider
$categories_menu_divider = apply_filters( 'nm_shop_categories_divider', '<span>⁄</span>' );
foreach( $categories as $category ) {
// Is this a sub-category?
if ( $category->parent != '0' ) {
// Should sub-categories be included?
if ( $hide_sub ) {
continue; // Skip to next loop item
} else {
if (
$category->parent == $current_cat_id || // Include current sub-category's children
! $category_has_children && $category->parent == $wp_query->queried_object->parent // Include categories with the same parent (if current sub-category doesn't have children)
) {
$output_sub_cat .= nm_category_menu_create_list( $category, $current_cat_id, $categories_menu_divider );
} else if (
$category->term_id == $current_cat_id // Include current sub-category (save in a separate variable so it can be appended to the start of the category list)
) {
$output_current_sub_cat = nm_category_menu_create_list( $category, $current_cat_id, $categories_menu_divider );
}
}
} else {
$output_cat .= nm_category_menu_create_list( $category, $current_cat_id, $categories_menu_divider, $current_top_cat_id );
}
}
if ( strlen( $output_sub_cat ) > 0 ) {
$output_sub_cat = '<ul class="nm-shop-sub-categories">' . $output_current_sub_cat . $output_sub_cat . '</ul>';
}
$output = $output_cat . $output_sub_cat;
echo $output;
}
}
Is it possible to rewrite the function to generate a dropdown menu instead of the shown menu?
As you can see in the screenshot the css class
<ul class="nm-shop-sub-categories">
<li>item_1</li>
<li>item_2</li>
</ul>
is not inside the parent listing. But I want it to be like this structure:
<ul class="nm-shop-categories">
<li>parent_item_1</li>
<ul class="nm-shop-sub-categories">
<li>sub_item_1</li>
<li>sub_item_2</li>
</ul>
<li>parent_item_2</li>
</ul>
Since in my code is no classic html I don't know how to change that via php. Any ideas?
Or is there no need to change the structure and I can use css to make change this menu into a clssic dropdown menu?
Update: I've made the changes mentioned by Norman. But it didn't solved the problem. The subcategories are still seperate from the parent ul elements.
In addition to the fist block of code I've found a second one relating to subcategories. Maybe this would be of any help?
/*
* Product category menu: Output sub-categories
*/
if ( ! function_exists( 'nm_sub_category_menu_output' ) ) {
function nm_sub_category_menu_output( $current_cat_id, $hide_empty ) {
global $wp_query, $nm_theme_options;
// Categories menu divider
$categories_menu_divider = apply_filters( 'nm_shop_categories_divider', '<span>⁄</span>' );
$output_sub_categories = '';
// Categories order
$orderby = 'slug';
$order = 'asc';
if ( isset( $nm_theme_options['shop_categories_orderby'] ) ) {
$orderby = $nm_theme_options['shop_categories_orderby'];
$order = $nm_theme_options['shop_categories_order'];
}
$sub_categories = get_categories( array(
'type' => 'post',
'parent' => $current_cat_id,
'orderby' => $orderby, // Note: 'name' sorts by product category "menu/sort order"
'order' => $order,
'hide_empty' => $hide_empty,
'hierarchical' => 1,
'taxonomy' => 'product_cat'
) );
$has_sub_categories = ( empty( $sub_categories ) ) ? false : true;
// Is there any sub-categories available
if ( $has_sub_categories ) {
//$current_cat_name = __( 'All', 'nm-framework' );
$current_cat_name = apply_filters( 'nm_shop_parent_category_title', $wp_query->queried_object->name );
foreach( $sub_categories as $sub_category ) {
$output_sub_categories .= nm_category_menu_create_list( $sub_category, $current_cat_id, $categories_menu_divider );
}
} else {
$current_cat_name = $wp_query->queried_object->name;
}
// "Back" link
$output_back_link = '';
if ( $nm_theme_options['shop_categories_back_link'] ) {
$parent_cat_id = $wp_query->queried_object->parent;
if ( $parent_cat_id ) {
// Back to parent-category link
$parent_cat_url = get_term_link( (int) $parent_cat_id, 'product_cat' );
$output_back_link = nm_sub_category_menu_back_link( $parent_cat_url, $categories_menu_divider );
} else if ( $nm_theme_options['shop_categories_back_link'] == '1st' ) {
// 1st sub-level - Back to top-level (main shop page) link
$shop_page_id = wc_get_page_id( 'shop' );
$shop_url = get_permalink( $shop_page_id );
$output_back_link = nm_sub_category_menu_back_link( $shop_url, $categories_menu_divider, ' 1st-level' );
}
}
// Current category link
$current_cat_url = get_term_link( (int) $current_cat_id, 'product_cat' );
$output_current_cat = '<li class="current-cat">' . esc_html( $current_cat_name ) . '</li>';
echo $output_back_link . $output_current_cat . $output_sub_categories;
}
}
Structure you required is not the best to manage with CSS
As per the code assumption it seems like you need below structure as the resultant.
<ul class="nm-shop-categories">
<li>parent_item_1
<ul class="nm-shop-sub-categories">
<li>sub_item_1</li>
<li>sub_item_2</li>
</ul>
</li>
<li>parent_item_2</li>
</ul>
To achieve the above structure, i would suggest you to change the line this
$output_cat = '<li' . $all_categories_class . '>' . esc_html__( 'All', 'nm-framework' ) . '</li>';
To
$output_cat = '<li' . $all_categories_class . '>';
$output_cat .= '' . esc_html__( 'All', 'nm-framework' ) . '';
And End of output
$output = $output_cat . $output_sub_cat;
To
$output = $output_cat . $output_sub_cat .'</li>';

Adding 'sort by' drop down on custom page using woocommerce short code

I have created a custom page using woocommerce short code for product categories. At the moment, it's pretty sparse as I've only just started on the new site.
I just need the default 'sort by' drop down element adding but have no idea how to do it.
I found some code here >>Woocommerce, sort dropdown on shortcode based product lists
and it certainly placed the drop down I need on the site (although I'd like it aligned left).
The only problem now, is that it's displaying the products with enormous images and all in a single vertical column.
I'm not a PHP programmer and am wondering if I've deleted some important code in the php file I modified. (thank god I took a copy of the original!).
Can anyone help? Is there a better way to add the sort by drop down onto my custom pages?
This is one of the pages I've created >> http://www.sdmtest1.co.uk/notebooks-journals/
Here is the code I added.
/**
* List products in a category shortcode
*
* #param array $atts
* #return string
*/
public static function product_category( $atts ) {
$atts = shortcode_atts( array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'title',
'order' => 'desc',
'category' => '', // Slugs
'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
), $atts );
if ( ! $atts['category'] ) {
return '';
}
// Default ordering args
$ordering_args = WC()->query->get_catalog_ordering_args( $atts['orderby'],
$atts['order'] );
$orderby = 'title';
$order = 'asc';
if ( isset( $_GET['orderby'] ) ) {
$getorderby = $_GET['orderby'];
}
if ($getorderby == 'popularity') {
$orderby = 'meta_value_num';
$order = 'desc';
$meta_key = 'total_sales';
} elseif ($getorderby == 'rating') {
$fields .= ", AVG( $wpdb->commentmeta.meta_value ) as average_rating ";
$where .= " AND ( $wpdb->commentmeta.meta_key = 'rating' OR $wpdb->commentmeta.meta_key IS null ) ";
$join .= "
LEFT OUTER JOIN $wpdb->comments ON($wpdb->posts.ID = $wpdb->comments.comment_post_ID)
LEFT JOIN $wpdb->commentmeta ON($wpdb->comments.comment_ID = $wpdb->commentmeta.comment_id)
";
$orderby = "average_rating DESC, $wpdb->posts.post_date DESC";
$groupby = "$wpdb->posts.ID";
} elseif ($getorderby == 'date') {
$orderby = 'date';
$order = 'desc';
} elseif ($getorderby == 'price') {
$orderby = 'meta_value_num';
$order = 'asc';
$meta_key = '_price';
} elseif ($getorderby == 'price-desc') {
$orderby = 'meta_value_num';
$order = 'desc';
$meta_key = '_price';
}
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'orderby' => $orderby, // $ordering_args['orderby'],
'order' => $order, // $ordering_args['order'],
'meta_key' => $meta_key,
'fields' => $fields,
'where' => $where,
'join' => $join,
'groupby' => $groupby,
'posts_per_page' => $per_page,
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
),
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => array( esc_attr( $category ) ),
'field' => 'slug',
'operator' => $operator
)
)
);
if ( isset( $ordering_args['meta_key'] ) ) {
$args['meta_key'] = $ordering_args['meta_key'];
}
ob_start();
$products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $args, $atts ) );
$woocommerce_loop['columns'] = $columns;
if ( $products->have_posts() ) : ?>
<div style="width:100%;">
<div style="float:right">
<form class="woocommerce-ordering" method="get">
<select name="orderby" class="orderby">
<?php
$catalog_orderby = apply_filters( 'woocommerce_catalog_orderby', array(
'menu_order' => __( 'Default sorting', 'woocommerce' ),
'popularity' => __( 'Sort by popularity', 'woocommerce' ),
'rating' => __( 'Sort by average rating', 'woocommerce' ),
'date' => __( 'Sort by newness', 'woocommerce' ),
'price' => __( 'Sort by price: low to high', 'woocommerce' ),
'price-desc' => __( 'Sort by price: high to low', 'woocommerce' )
) );
if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' )
unset( $catalog_orderby['rating'] );
foreach ( $catalog_orderby as $id => $name )
echo '<option value="' . esc_attr( $id ) . '" ' . selected( $getorderby, $id, false ) . '>' . esc_attr( $name ) . '</option>';
?>
</select>
<?php
// Keep query string vars intact
foreach ( $_GET as $key => $val ) {
if ( 'orderby' === $key || 'submit' === $key )
continue;
if ( is_array( $val ) ) {
foreach( $val as $innerVal ) {
echo '<input type="hidden" name="' . esc_attr( $key ) . '[]" value="' . esc_attr( $innerVal ) . '" />';
}
} else {
echo '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $val ) . '" />';
}
}
?>
</form>
</div>
</div>
<div style="clear:both;"></div>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php endif;
woocommerce_reset_loop();
wp_reset_postdata();
return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
}
I edited in dreamweaver and it flagged a syntax error. I wasn't sure where the code I pasted was to begin and end and I kinda lost this bit in the process.
// Remove ordering query arguments
WC()->query->remove_ordering_args();
return $return;
}
Thanks,
Loren
If you add the paginate="true" attribute to your [products] shortcode, then the shortcode, then the Sort by dropdown menu will appear on the page.
I have created a custom page using woocommerce short code for product categories.
You say you're using shortcodes, but you don't provide an example. So I'll make one up.
If you were using this to display all of the products in the "boots" category:
[product_category category="boots"]
Then change it to this:
[product_category category="boots" paginate="true"]

Adding a link into wordpress shortcode

i have a shortcode that posts recent blog entries from a certain category on one of my web pages, however i want to display a static link at the end of everypost, is there anyway to do this?
the following code is used to display the posts:
<?php echo do_shortcode('[display-posts category="competitions" posts_per_page="4" include_excerpt="true" image_size="thumbnail" wrapper="ul"]');
Thanks in advance.
<?php
// Create the shortcode
add_shortcode( 'display-posts', 'be_display_posts_shortcode' );
function be_display_posts_shortcode( $atts ) {
// Original Attributes, for filters
$original_atts = $atts;
// Pull in shortcode attributes and set defaults
$atts = shortcode_atts( array(
'title' => '',
'author' => '',
'category' => '',
'date_format' => '(n/j/Y)',
'display_posts_off' => false,
'exclude_current' => false,
'id' => false,
'ignore_sticky_posts' => false,
'image_size' => false,
'include_title' => true,
'include_author' => false,
'include_content' => false,
'include_date' => false,
'include_excerpt' => false,
'meta_key' => '',
'meta_value' => '',
'no_posts_message' => '',
'offset' => 0,
'order' => 'DESC',
'orderby' => 'date',
'post_parent' => false,
'post_status' => 'publish',
'post_type' => 'post',
'posts_per_page' => '10',
'tag' => '',
'tax_operator' => 'IN',
'tax_term' => false,
'taxonomy' => false,
'wrapper' => 'ul',
'wrapper_class' => 'display-posts-listing',
'wrapper_id' => false,
), $atts, 'display-posts' );
// End early if shortcode should be turned off
if( $atts['display_posts_off'] )
return;
$shortcode_title = sanitize_text_field( $atts['title'] );
$author = sanitize_text_field( $atts['author'] );
$category = sanitize_text_field( $atts['category'] );
$date_format = sanitize_text_field( $atts['date_format'] );
$exclude_current = be_display_posts_bool( $atts['exclude_current'] );
$id = $atts['id']; // Sanitized later as an array of integers
$ignore_sticky_posts = be_display_posts_bool( $atts['ignore_sticky_posts'] );
$image_size = sanitize_key( $atts['image_size'] );
$include_title = be_display_posts_bool( $atts['include_title'] );
$include_author = be_display_posts_bool( $atts['include_author'] );
$include_content = be_display_posts_bool( $atts['include_content'] );
$include_date = be_display_posts_bool( $atts['include_date'] );
$include_excerpt = be_display_posts_bool( $atts['include_excerpt'] );
$meta_key = sanitize_text_field( $atts['meta_key'] );
$meta_value = sanitize_text_field( $atts['meta_value'] );
$no_posts_message = sanitize_text_field( $atts['no_posts_message'] );
$offset = intval( $atts['offset'] );
$order = sanitize_key( $atts['order'] );
$orderby = sanitize_key( $atts['orderby'] );
$post_parent = $atts['post_parent']; // Validated later, after check for 'current'
$post_status = $atts['post_status']; // Validated later as one of a few values
$post_type = sanitize_text_field( $atts['post_type'] );
$posts_per_page = intval( $atts['posts_per_page'] );
$tag = sanitize_text_field( $atts['tag'] );
$tax_operator = $atts['tax_operator']; // Validated later as one of a few values
$tax_term = sanitize_text_field( $atts['tax_term'] );
$taxonomy = sanitize_key( $atts['taxonomy'] );
$wrapper = sanitize_text_field( $atts['wrapper'] );
$wrapper_class = sanitize_html_class( $atts['wrapper_class'] );
if( !empty( $wrapper_class ) )
$wrapper_class = ' class="' . $wrapper_class . '"';
$wrapper_id = sanitize_html_class( $atts['wrapper_id'] );
if( !empty( $wrapper_id ) )
$wrapper_id = ' id="' . $wrapper_id . '"';
// Set up initial query for post
$args = array(
'category_name' => $category,
'order' => $order,
'orderby' => $orderby,
'post_type' => explode( ',', $post_type ),
'posts_per_page' => $posts_per_page,
'tag' => $tag,
);
// Ignore Sticky Posts
if( $ignore_sticky_posts )
$args['ignore_sticky_posts'] = true;
// Meta key (for ordering)
if( !empty( $meta_key ) )
$args['meta_key'] = $meta_key;
// Meta value (for simple meta queries)
if( !empty( $meta_value ) )
$args['meta_value'] = $meta_value;
// If Post IDs
if( $id ) {
$posts_in = array_map( 'intval', explode( ',', $id ) );
$args['post__in'] = $posts_in;
}
// If Exclude Current
if( $exclude_current )
$args['post__not_in'] = array( get_the_ID() );
// Post Author
if( !empty( $author ) )
$args['author_name'] = $author;
// Offset
if( !empty( $offset ) )
$args['offset'] = $offset;
// Post Status
$post_status = explode( ', ', $post_status );
$validated = array();
$available = array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash', 'any' );
foreach ( $post_status as $unvalidated )
if ( in_array( $unvalidated, $available ) )
$validated[] = $unvalidated;
if( !empty( $validated ) )
$args['post_status'] = $validated;
// If taxonomy attributes, create a taxonomy query
if ( !empty( $taxonomy ) && !empty( $tax_term ) ) {
// Term string to array
$tax_term = explode( ', ', $tax_term );
// Validate operator
if( !in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) )
$tax_operator = 'IN';
$tax_args = array(
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $tax_term,
'operator' => $tax_operator
)
)
);
// Check for multiple taxonomy queries
$count = 2;
$more_tax_queries = false;
while(
isset( $original_atts['taxonomy_' . $count] ) && !empty( $original_atts['taxonomy_' . $count] ) &&
isset( $original_atts['tax_' . $count . '_term'] ) && !empty( $original_atts['tax_' . $count . '_term'] )
):
// Sanitize values
$more_tax_queries = true;
$taxonomy = sanitize_key( $original_atts['taxonomy_' . $count] );
$terms = explode( ', ', sanitize_text_field( $original_atts['tax_' . $count . '_term'] ) );
$tax_operator = isset( $original_atts['tax_' . $count . '_operator'] ) ? $original_atts['tax_' . $count . '_operator'] : 'IN';
$tax_operator = in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ? $tax_operator : 'IN';
$tax_args['tax_query'][] = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $terms,
'operator' => $tax_operator
);
$count++;
endwhile;
if( $more_tax_queries ):
$tax_relation = 'AND';
if( isset( $original_atts['tax_relation'] ) && in_array( $original_atts['tax_relation'], array( 'AND', 'OR' ) ) )
$tax_relation = $original_atts['tax_relation'];
$args['tax_query']['relation'] = $tax_relation;
endif;
$args = array_merge( $args, $tax_args );
}
// If post parent attribute, set up parent
if( $post_parent ) {
if( 'current' == $post_parent ) {
global $post;
$post_parent = get_the_ID();
}
$args['post_parent'] = intval( $post_parent );
}
// Set up html elements used to wrap the posts.
// Default is ul/li, but can also be ol/li and div/div
$wrapper_options = array( 'ul', 'ol', 'div' );
if( ! in_array( $wrapper, $wrapper_options ) )
$wrapper = 'ul';
$inner_wrapper = 'div' == $wrapper ? 'div' : 'li';
$listing = new WP_Query( apply_filters( 'display_posts_shortcode_args', $args, $original_atts ) );
if ( ! $listing->have_posts() )
return apply_filters( 'display_posts_shortcode_no_results', wpautop( $no_posts_message ) );
$inner = '';
while ( $listing->have_posts() ): $listing->the_post(); global $post;
$image = $date = $author = $excerpt = $content = '';
if ( $include_title )
$title = '<a class="title" href="' . apply_filters( 'the_permalink', get_permalink() ) . '">' . get_the_title() . '</a>';
if ( $image_size && has_post_thumbnail() )
$image = '<a class="image" href="' . get_permalink() . '">' . get_the_post_thumbnail( get_the_ID(), $image_size ) . '</a> ';
if ( $include_date )
$date = ' <span class="date">' . get_the_date( $date_format ) . '</span>';
if( $include_author )
$author = apply_filters( 'display_posts_shortcode_author', ' <span class="author">by ' . get_the_author() . '</span>' );
if ( $include_excerpt )
$excerpt = ' <span class="excerpt-dash">-</span> <span class="excerpt">' . get_the_excerpt() . '</span>';
if( $include_content ) {
add_filter( 'shortcode_atts_display-posts', 'be_display_posts_off', 10, 3 );
$content = '<div class="content">' . apply_filters( 'the_content', get_the_content() ) . '</div>';
remove_filter( 'shortcode_atts_display-posts', 'be_display_posts_off', 10, 3 );
}
$class = array( 'listing-item' );
$class = sanitize_html_class( apply_filters( 'display_posts_shortcode_post_class', $class, $post, $listing, $original_atts ) );
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $excerpt . $content . '</' . $inner_wrapper . '>';
// If post is set to private, only show to logged in users
if( 'private' == get_post_status( get_the_ID() ) && !current_user_can( 'read_private_posts' ) )
$output = '';
$inner .= apply_filters( 'display_posts_shortcode_output', $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class );
endwhile; wp_reset_postdata();
$open = apply_filters( 'display_posts_shortcode_wrapper_open', '<' . $wrapper . $wrapper_class . $wrapper_id . '>', $original_atts );
$close = apply_filters( 'display_posts_shortcode_wrapper_close', '</' . $wrapper . '>', $original_atts );
$return = $open;
if( $shortcode_title ) {
$title_tag = apply_filters( 'display_posts_shortcode_title_tag', 'h2', $original_atts );
$return .= '<' . $title_tag . ' class="display-posts-title">' . $shortcode_title . '</' . $title_tag . '>' . "\n";
}
$return .= $inner . $close;
return $return;
}
/**
* Turn off display posts shortcode
* If display full post content, any uses of [display-posts] are disabled
*
* #param array $out, returned shortcode values
* #param array $pairs, list of supported attributes and their defaults
* #param array $atts, original shortcode attributes
* #return array $out
*/
function be_display_posts_off( $out, $pairs, $atts ) {
$out['display_posts_off'] = true;
return $out;
}
/**
* Convert string to boolean
* because (bool) "false" == true
*
*/
function be_display_posts_bool( $value ) {
return !empty( $value ) && 'true' == $value ? true : false;
}
You'll want to edit you $output variable which is on line 243 on the code you've given above.
A simple amendment to add a static url will do fine, something like this:
$static_link = 'http://www.test.com/test';
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $excerpt . $content . 'Read more' . '</' . $inner_wrapper . '>';
Amend this to your requirements, say adding a proper link from the database.
Hope this helps.

Customising excerpt in theme

I've been reading a lot of how to customize excerpt function in WordPress but I have no idea how to proceed with this.
The theme that I am using already have 4 pre-customized excerpt functions and the one that I will show here is closest to my desired but still needs to improve.
My question is how to stop erasing HTML formating from my content (line breaks, paragraphs, font variants, etc)?
add_shortcode('display_news_s5', 'be_display_posts_shortcode5');
function be_display_posts_shortcode5($atts) {
// Pull in shortcode attributes and set defaults
extract( shortcode_atts( array(
'post_type' => 'post',
'post_parent' => false,
'id' => false,
'tag' => '',
'category' => '',
'offset' => 0,
'posts_per_page' => '1',
'order' => 'DESC',
'orderby' => 'date',
'include_date' => false,
'include_excerpt' => false,
'excerpt_l' => 8,
'taxonomy' => false,
'tax_term' => true,
'tax_operator' => 'IN'
), $atts ) );
// Set up initial query for post
$args = array(
'post_type' => explode( ',', $post_type ),
'tag' => $tag,
'category_name' => $category,
'p' => $id,
'posts_per_page' => $posts_per_page,
'order' => $order,
'orderby' => $orderby,
'offset' => $offset
);
// If Post IDs
if( $id ) {
$posts_in = explode( ',', $id );
$args['post__in'] = $posts_in;
}
// If taxonomy attributes, create a taxonomy query
if ( !empty( $taxonomy ) && !empty( $tax_term ) ) {
// Term string to array
$tax_term = explode( ', ', $tax_term );
// Validate operator
if( !in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) )
$tax_operator = 'IN';
$tax_args = array(
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $tax_term,
'operator' => $tax_operator
)
)
);
$args = array_merge( $args, $tax_args );
}
// If post parent attribute, set up parent
if( $post_parent ) {
if( 'current' == $post_parent ) {
global $post;
$post_parent = $post->ID;
}
$args['post_parent'] = $post_parent;
}
$listing = new WP_Query( apply_filters( 'display_posts_shortcode_args', $args, $atts ) );
$count = 0;
if ( !$listing->have_posts() )
return apply_filters ('display_posts_shortcode_no_results', false );
$inner = '';
while ( $listing->have_posts() ): $listing->the_post(); global $post;
$count++;
if( $count == 1 ){
$style = ' news-main-post';
} else {
$style = ' news-list-posts';
}
$title = '<div class="news-listing-title"><a class="title" href="'. get_permalink() .'">'. get_the_title() .'</a></div>';
if ($include_date == 'true') $date = ' <div class="news-listing-meta"><span class="news-listing-date">'. get_the_date() . '</span><span class="news-listing-comment">('. get_comments_number() .')</span></div>';
else $date = '';
if ($include_excerpt == 'true') $excerpt = '<span>' .excerpt($excerpt_l) . '</span>';
else $excerpt = '';
$output = '<div class="news-listing' . $style . '"><div class="news-listing-item">'. $title . $excerpt . $date . '</div></div>';
$inner .= apply_filters( 'display_posts_shortcode_output', $output, $atts, $title, $excerpt, $date );
endwhile; wp_reset_query();
$open = apply_filters( 'display_posts_shortcode_wrapper_open', '<div class="news-listing-wrapper-s3">' );
$close = apply_filters( 'display_posts_shortcode_wrapper_close', '<div class="clear"></div></div>' );
$return = $open . $inner . $close;
return $return;
}
Have a look here: LINK looks like its doing what you want to acchieve.

Categories