I'm very new to the process of CSS & PHP but with Wordpress & the widgets I'm trying to get better with my plugins.
I am trying to get my little twitter bird to appear next to my twitter content message, but it continues to be at the top of the messages.
An example of what I'm trying to achieve can be located here. http://globe-trekking.com/twitter_ideal.jpg (can't add image because this is my first post)
How can I over come this.
My relevant PHP code is:
$widgetContent .= "<span class='entry-content'><img class='twitter_bird' src='http://globe-trekking.com/running/wp-content/themes/newscast/images/bird_blue_16.png'>{$entryContent}</span>";
the full PHP code is:
$widgetContent .= '<ul>';
if ( ! is_array( $tweets ) || count( $tweets ) == 0 ) {
$widgetContent .= '<li class="wpTwitterWidgetEmpty">' . __( 'No Tweets Available', $this->_slug ) . '</li>';
} else {
$count = 0;
foreach ( $tweets as $tweet ) {
// Set our "ago" string which converts the date to "# ___(s) ago"
$tweet->ago = $this->_timeSince( strtotime( $tweet->created_at ), $args['showts'], $args['dateFormat'] );
//$entryContent .= '<li>';
$entryContent = apply_filters( 'widget_twitter_content', $tweet->text, $tweet );
$widgetContent .= "<span class='entry-content'><img class='twitter_bird' src='http://globe-trekking.com/running/wp-content/themes/newscast/images/bird_blue_16.png'>{$entryContent}</span>";
$widgetContent .= " <span class='entry-meta'>";
$widgetContent .= "<span class='time-meta'>";
$linkAttrs = array(
'href' => "http://twitter.com/{$tweet->user->screen_name}/statuses/{$tweet->id_str}"
);
$widgetContent .= $this->_buildLink( $tweet->ago, $linkAttrs );
$widgetContent .= '</span>';
if ( 'true' != $args['hidefrom'] ) {
$from = sprintf( __( 'from %s', $this->_slug ), str_replace( '&', '&', $tweet->source ) );
$widgetContent .= " <span class='from-meta'>{$from}</span>";
}
if ( !empty( $tweet->in_reply_to_screen_name ) ) {
$rtLinkText = sprintf( __( 'in reply to %s', $this->_slug ), $tweet->in_reply_to_screen_name );
$widgetContent .= ' <span class="in-reply-to-meta">';
$linkAttrs = array(
'href' => "http://twitter.com/{$tweet->in_reply_to_screen_name}/statuses/{$tweet->in_reply_to_status_id_str}",
'class' => 'reply-to'
);
$widgetContent .= $this->_buildLink( $rtLinkText, $linkAttrs );
$widgetContent .= '</span>';
}
$widgetContent .= '</span>';
if ( 'true' == $args['showintents'] ) {
$widgetContent .= ' <span class="intent-meta">';
$lang = $this->_getTwitterLang();
if ( !empty( $lang ) )
$linkAttrs['data-lang'] = $lang;
$linkText = __( 'Reply', $this->_slug );
$linkAttrs['href'] = "http://twitter.com/intent/tweet?in_reply_to={$tweet->id_str}";
$linkAttrs['class'] = 'in-reply-to';
$linkAttrs['title'] = $linkText;
$widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
$linkText = __( 'Retweet', $this->_slug );
$linkAttrs['href'] = "http://twitter.com/intent/retweet?tweet_id={$tweet->id_str}";
$linkAttrs['class'] = 'retweet';
$linkAttrs['title'] = $linkText;
$widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
$linkText = __( 'Favorite', $this->_slug );
$linkAttrs['href'] = "http://twitter.com/intent/favorite?tweet_id={$tweet->id_str}";
$linkAttrs['class'] = 'favorite';
$linkAttrs['title'] = $linkText;
$widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
$widgetContent .= '</span>';
}
//$widgetContent .= '</li>';
if ( ++$count >= $args['items'] )
break;
}
}
$widgetContent .= '</ul>';
My CSS code is:
.widget_twitter div {
padding:0;
width:280px;
}
.widget_twitter ul li {
margin-bottom:5px;
margin-left:0px;
clear:both;
}
.widget_twitter a {
text-decoration:none;
color:#333333;
margin: 0 10px 10px 0;
}
.widget_twitter a:visited {
text-decoration:underline;
color:#FF00FF;
}
.widget_twitter a:hover {
text-decoration:underline;
color:#0000CC;
}
.widget_twitter .follow-button,
.widget_twitter .xavisys-link {
margin:0 10px 10px 25px;
}
.widget_twitter .entry-content {
width:260px;
display: inline-block;
line-height:22px;
margin-top:10px;
margin-left: 13px;
}
.widget_twitter .entry-content twitter_bird {
vertical-align:middle;
}
.widget_twitter .entry-meta {
display:block;
font-size:80%;
margin-bottom: 10px;
margin-left: 13px;
}
.widget_twitter .intent-meta a {
background-image: url('images/everything-spritev2.png'); /** from Twitter resources */
display: inline-block;
text-indent: -9999px;
margin: 0 10px 10px 0;
height: 16px;
width: 16px;
}
.widget_twitter .in-reply-to-meta {
margin: 0 10px 10px 0;
}
.widget_twitter .intent-meta a.in-reply-to {
background-position: 0 center;
}
.widget_twitter .intent-meta a:hover.in-reply-to {
background-position: -16px center;
}
.widget_twitter .intent-meta a.favorite {
background-position: -32px center;
}
.widget_twitter .intent-meta a:hover.favorite {
background-position: -48px center;
}
.widget_twitter .intent-meta a.retweet {
background-position: -80px center;
}
.widget_twitter .intent-meta a:hover.retweet {
background-position: -96px center;
}
Any assistance would be greatly appreciated. I've managed to get it to a "decent" appearance, but otherwise, this is the last step that I've tried a number of things on.
Regards,
Daniël
Sorry for fast answer, may be me wrong, but try to use float:left for bird image.
Related
I use the code below to display images in posts. It basically works, but changes made via "Add Image" are no longer saved since WP 6.0 or 6.1.
The manual variant via the "post_banner_image" field below by entering the image ID still works.
here a front-end screenshot
<?php
// Add Meta Box to post
add_action( 'add_meta_boxes', 'multi_media_uploader_meta_box' );
function multi_media_uploader_meta_box() {
add_meta_box( 'my-post-box', 'Media Field', 'multi_media_uploader_meta_box_func', 'post', 'normal', 'high' );
}
function multi_media_uploader_meta_box_func($post) {
$banner_img = get_post_meta($post->ID,'post_banner_img', true);
?>
<style type="text/css">
.multi-upload-medias ul li .delete-img { position: absolute; right: 3px; top: 2px; background: aliceblue; border-radius: 50%; cursor: pointer; font-size: 14px; line-height: 20px; color: red; }
.multi-upload-medias ul li { width: 120px; display: inline-block; vertical-align: middle; margin: 5px; position: relative; }
.multi-upload-medias ul li img { width: 100%; }
</style>
<table cellspacing="10" cellpadding="10">
<tr>
<td>Banner Image</td>
<td>
<?php echo multi_media_uploader_field( 'post_banner_img', $banner_img ); ?>
</td>
</tr>
</table>
<script type="text/javascript">
jQuery(function($) {
$('body').on('click', '.wc_multi_upload_image_button', function(e) {
e.preventDefault();
var button = $(this),
custom_uploader = wp.media({
title: 'Insert image',
button: { text: 'Use this image' },
multiple: true
}).on('select', function() {
var attech_ids = '';
attachments
var attachments = custom_uploader.state().get('selection'),
attachment_ids = new Array(),
i = 0;
attachments.each(function(attachment) {
attachment_ids[i] = attachment['id'];
attech_ids += ',' + attachment['id'];
if (attachment.attributes.type == 'image') {
$(button).siblings('ul').append('<li data-attechment-id="' + attachment['id'] + '"><img class="true_pre_image" src="' + attachment.attributes.url + '" /><i class=" dashicons dashicons-no delete-img"></i></li>');
} else {
$(button).siblings('ul').append('<li data-attechment-id="' + attachment['id'] + '"><img class="true_pre_image" src="' + attachment.attributes.icon + '" /><i class=" dashicons dashicons-no delete-img"></i></li>');
}
i++;
});
var ids = $(button).siblings('.attechments-ids').attr('value');
if (ids) {
var ids = ids + attech_ids;
$(button).siblings('.attechments-ids').attr('value', ids);
} else {
$(button).siblings('.attechments-ids').attr('value', attachment_ids);
}
$(button).siblings('.wc_multi_remove_image_button').show();
})
.open();
});
$('body').on('click', '.wc_multi_remove_image_button', function() {
$(this).hide().prev().val('').prev().addClass('button').html('Add Media');
$(this).parent().find('ul').empty();
return false;
});
});
jQuery(document).ready(function() {
jQuery(document).on('click', '.multi-upload-medias ul li i.delete-img', function() {
var ids = [];
var this_c = jQuery(this);
jQuery(this).parent().remove();
jQuery('.multi-upload-medias ul li').each(function() {
ids.push(jQuery(this).attr('data-attechment-id'));
});
jQuery('.multi-upload-medias').find('input[type="hidden"]').attr('value', ids);
});
})
</script>
<?php
}
function multi_media_uploader_field($name, $value = '') {
$image = '">Add Media';
$image_str = '';
$image_size = 'full';
$display = 'none';
$value = explode(',', $value);
if (!empty($value)) {
foreach ($value as $values) {
if ($image_attributes = wp_get_attachment_image_src($values, $image_size)) {
$image_str .= '<li data-attechment-id=' . $values . '><img src="' . $image_attributes[0] . '" /><i class="dashicons dashicons-no delete-img"></i></li>';
}
}
}
if($image_str){
$display = 'inline-block';
}
return '<div class="multi-upload-medias"><ul>' . $image_str . '</ul>Remove media</div>';
}
// Save Meta Box values.
add_action( 'save_post', 'wc_meta_box_save' );
function wc_meta_box_save( $post_id ) {
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if( !current_user_can( 'edit_post' ) ){
return;
}
if( isset( $_POST['post_banner_img'] ) ){
update_post_meta( $post_id, 'post_banner_img', $_POST['post_banner_img'] );
}
}
?>
Can someone help me to get the other part working again?
current_user_can('edit_post') is no longer valid in WordPress 6.1. Here's the relevant core trac ticket.
You must now use one of these formats:
current_user_can( 'edit_posts' );
current_user_can( 'edit_post', $post->ID );
current_user_can( 'edit_post_meta', $post->ID, $meta_key );
I've been trying to add repeater fields in my wordpress widget form. I found two plugin examples but they don't work anymore. When I click on "Add row", nothing happens.
https://www.commoninja.com/discover/wordpress/plugin/social-repeater-widget
https://www.zealousweb.com/wordpress-plugins/repeater-entries-widget/
I noticed both use jquery in their widgets which I guess doesn't work anymore in the newer Wordpress versions?
/**
* Back-end widget form.
*
* #see WP_Widget::form()
*
* #param array $instance Previously saved values from database.
*/
public function form($instance)
{
$max_entries = get_option( 'max_entries' );
$max_entries = (empty($max_entries)) ? '5' : $max_entries;
$widget_add_id = $this->id . "-add";
$title = !empty($instance['title']) ? $instance['title'] : __('Social Repeater Widget', 'srw-widget');
$srw_html = '<p>';
$srw_html .= '<label for="'.$this->get_field_id('title').'"> '. __( 'Widget Title', 'srw-widget' ) .' :</label>';
$srw_html .= '<input id="'.$this->get_field_id('title').'" name="'.$this->get_field_name('title').'" type="text" value="'.$title.'" />';
$srw_html .= '<div class="'.$widget_add_id.'-input-containers"><div id="entries">';
for( $i =0; $i<$max_entries; $i++){
if(isset($instance['block-' . $i]) || isset($instance['social_platform-' . $i]))
{
$srw_tab_title = !empty($instance['social_platform-' . $i]) ? $instance['social_platform-' . $i] : __( 'Add Social Profile Details', 'srw-widget' );
$display = (!isset($instance['block-' . $i]) || ($instance['block-' . $i] == "")) ? 'style="display:none;"' : '';
$srw_html .= '<div id="entry'.($i+1).'" '.$display.' class="entrys"><span class="entry-title" onclick = "slider(this);"> '.$srw_tab_title.' </span>';
$srw_html .= '<div class="entry-desc cf">';
$srw_html .= '<input id="'.$this->get_field_id('block-' . $i ).'" name="'.$this->get_field_name('block-' . $i ).'" type="hidden" value="'.$instance['block-' . $i].'">';
$social_platform = esc_attr( $instance['social_platform-' . $i] );
$social_platform_link = esc_attr( $instance['social_platform_link-' . $i] );
$srw_html .= '<p class="last desc">';
$srw_html .= '<label for="'.$this->get_field_id('social_platform-' . $i).'"> '. __( 'Social Platform', 'srw-widget' ) .' :</label>';
$srw_html .= '<input class="widefat" id="'.$this->get_field_id('social_platform-' . $i).'" name="'.$this->get_field_name('social_platform-' . $i).'" type="text" value="'.$social_platform.'" placeholder="'.__( 'Enter Social Platform name', 'srw-widget' ).'" />';
$srw_html .= '</p><p>';
$srw_html .= '<label for="'.$this->get_field_id('social_platform_link-' . $i).'"> '. __('Social platform Link', 'srw-widget' ) .' :</label>';
$srw_html .= '<input class="widefat" id="'.$this->get_field_id('social_platform_link-' . $i).'" name="'.$this->get_field_name('social_platform_link-' . $i).'" type="url" value="'.$social_platform_link.'" placeholder="'.__( 'Enter Social Platform Link', 'srw-widget' ).'"/>';
$srw_html .= '</p>';
/* end wrapper with delete entry option */
$srw_html .= '<p><span class="delete-row">'. __( 'Delete Row', 'srw-widget' ) .'</span></p>';
$srw_html .= '</div></div>';
}
}
$srw_html .= '</div></div>';
$srw_html .= '<div id="message">'. __( 'Sorry, you reached to the limit of','srw-widget') .' "'.$max_entries.'" '. __( 'maximum entries', 'srw-widget' ) .'.</div>' ;
$srw_html .= '<div class="'.$widget_add_id.'" style="display:none;">' . __('Add New Platform', 'srw-widget') . '</div>';
?>
<script>
jQuery(document).ready(function(e) {
jQuery.each(jQuery(".<?php echo $widget_add_id; ?>-input-containers #entries").children(), function(){
if(jQuery(this).find('input').val() != ''){
jQuery(this).show();
}
});
jQuery(".<?php echo $widget_add_id; ?>" ).bind('click', function(e) {
var rows = 0;
jQuery.each(jQuery(".<?php echo $widget_add_id; ?>-input-containers #entries").children(), function(){
if(jQuery(this).find('input').val() == ''){
jQuery(this).find(".entry-title").addClass("active");
jQuery(this).find(".entry-desc").slideDown();
jQuery(this).find('input').first().val('0');
jQuery(this).show();
return false;
}
else{
rows++;
jQuery(this).show();
jQuery(this).find(".entry-title").removeClass("active");
jQuery(this).find(".entry-desc").slideUp();
}
});
if(rows == '<?php echo $max_entries;?>')
{
jQuery("#rew_container #message").show();
}
});
jQuery(".delete-row" ).bind('click', function(e) {
var count = 1;
var current = jQuery(this).closest('.entrys').attr('id');
jQuery.each(jQuery("#entries #"+current+" .entry-desc").children(), function(){
jQuery(this).val('');
});
jQuery.each(jQuery("#entries #"+current+" .entry-desc p").children(), function(){
jQuery(this).val('');
});
jQuery('#entries #'+current+" .entry-title").removeClass('active');
jQuery('#entries #'+current+" .entry-desc").hide();
jQuery('#entries #'+current).remove();
jQuery.each(jQuery(".<?php echo $widget_add_id; ?>-input-containers #entries").children(), function(){
if(jQuery(this).find('input').val() != ''){
jQuery(this).find('input').first().val(count);
}
count++;
});
});
});
</script>
<style>
.cf:before, .cf:after { content: ""; display: table; }
.cf:after { clear: both; }
.cf { zoom: 1; }
.clear { clear: both; }
.clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
.clearfix { display: inline-block; }
* html .clearfix { height: 1%; }
.clearfix { display: block;}
#rew_container input,select,textarea{ float: right;width: 60%;}
#rew_container label{width:40%;}
<?php echo '.'.$widget_add_id; ?>{
background: #ccc none repeat scroll 0 0;font-weight: bold;margin: 20px 0px 9px;padding: 6px;text-align: center;display:block !important; cursor:pointer;
}
.desc{height:55px;}
#entries{ padding:10px 0 0;}
#entries .entrys{ padding:0; border:1px solid #e5e5e5; margin:10px 0 0; clear:both;}
#entries .entrys:first-child{ margin:0;}
#entries .delete-row{margin-top:20px;float:right;text-decoration: underline;color:red;}
#entries .entry-title{ display:block; font-size:14px; line-height:18px; font-weight:600; background:#f1f1f1; padding:7px 5px; position:relative;}
#entries .entry-title:after{ content: '\f140'; font: 400 20px/1 dashicons; position:absolute; right:10px; top:6px; color:#a0a5aa;}
#entries .entry-title.active:after{ content: '\f142';}
#entries .entry-desc{ display:none; padding:0 10px 10px; border-top:1px solid #e5e5e5;}
#rew_container #entries p.last label{ white-space: pre-line; float:left; width:39%;}
#message{padding:6px;display:none;color:red;font-weight:bold;}
</style>
<div id="rew_container">
<?php echo $srw_html;?>
</div>
<?php
}
I'm pretty new to php and wordpress so any help would be appreciated.
Please try the below code to create a repeater field in the widget.
dd_action( 'widgets_init', 'services_widget' );
function services_widget() {
register_widget( 'services_widget' );
}
class services_widget extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'services_widget',
'description' => 'Add a service description.'
);
$control_ops = array( 'width' => 400, 'height' => 350 );
parent::__construct( 'services_widget', 'Services', $widget_ops, $control_ops );
}
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
echo $args['before_widget'];
if ( ! empty( $title ) ) {
echo $args['before_title'] . $title . $args['after_title'];
}
if( have_rows('service', 'widget_' . $args['widget_id']) ):
echo '<ul>';
while ( have_rows('service', 'widget_' . $args['widget_id']) ) : the_row();
echo '<li class="service one-half">';
$title = get_sub_field( 'title', 'widget_' . $args['widget_id'] );
$body = get_sub_field( 'body', 'widget_' . $args['widget_id']);
$button = get_sub_field( 'button', 'widget_' . $args['widget_id'] );
$button_link = get_sub_field( 'button_link', 'widget_' . $args['widget_id'] );
if( $title ) {
echo '<h4>' . $title . '</h4>';
}
if( $body ) {
echo '<p>' . $body . '</p>';
}
if( $body ) {
echo '<a class="more" href="' . $button_link . '">' .$button . '</a>';
}
echo '</li><div class="clearfix"></div></ul>';
endwhile;
endif;
echo $args['after_widget'];
}
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
$filter = isset( $instance['filter'] ) ? $instance['filter'] : 0;
$title = sanitize_text_field( $instance['title'] );
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox"<?php checked( $filter ); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
if ( current_user_can( 'unfiltered_html' ) ) {
$instance['text'] = $new_instance['text'];
} else {
$instance['text'] = wp_kses_post( $new_instance['text'] );
}
$instance['filter'] = ! empty( $new_instance['filter'] );
return $instance;
}
}
I'm using the below code to make wordpress search only by product titles. However, the woocommerce "Filter by Attributes" widget still shows filters as if the search was done on body text too.
So for example if I search "face" the results that show up all have "face" in the title but the Filter By Attribute widget will still show Chocolate as an attribute because there is a chocolate bar that has a description "Face it, we all love chocolate"
Then if you click the "Chocolate" filter, it will show no results, because the search is only showing results with "face" in the title.
I don't even know where to begin looking to change the behaviour of the filter by attributes widget.
// Search titles only
function __search_by_title_only( $search, $wp_query )
{
global $wpdb;
if(empty($search)) {
return $search; // skip processing - no search term in query
}
$q = $wp_query->query_vars;
$n = !empty($q['exact']) ? '' : '%';
$search =
$searchand = '';
foreach ((array)$q['search_terms'] as $term) {
$term = esc_sql($wpdb->esc_like($term));
$search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
$searchand = ' AND ';
}
if (!empty($search)) {
$search = " AND ({$search}) ";
if (!is_user_logged_in())
$search .= " AND ($wpdb->posts.post_password = '') ";
}
return $search;
}
add_filter('posts_search', '__search_by_title_only', 500, 2);
I've cobbled together my own filter that plays nice with the above search (only the titles) and doesn't show any Brands that have items that don't have the keyword in the title. My only issue now is figuring out how to get the count of items.
<?php
$searchterm = htmlentities($_GET["s"]);
$filter_brand = htmlentities($_GET["filter_brand"]);
$current = $_SERVER['REQUEST_URI'];
$site_url = home_url();
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'title',
's' => $searchterm
);
// The Query
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ) :
echo'<div id="woocommerce_layered_nav-3" class="widget woocommerce widget_layered_nav woocommerce-widget-layered-nav">
<ul class="woocommerce-widget-layered-nav-list">';
$unique_singler = array();
while ( $the_query->have_posts() ) : $the_query->the_post();
$brand_terms = get_the_terms( $post, 'pa_brand' );
$singler = array_values($brand_terms)[0];
$name = $singler->name;
$name_string = strtolower($name);
$name_slug = str_replace(" ","-",$name_string);
// only create option if city hasn't been added yet
if( ! in_array( $name, $unique_singler ) ) :
// add city to array so it doesn't repeat
$unique_singler[] = $name;
;?>
<li class="woocommerce-widget-layered-nav-list__item wc-layered-nav-term <?php if (!($filter_brand == $name_slug) && !empty($filter_brand)) { echo 'hidden'; }?>">
<?php echo '<a class="remover ';
if ($filter_brand == $name_slug) { echo 'shown'; }
echo '" href="'.$site_url.'/?s='.$searchterm.'&tags=1&ixwps=1&post_type=product"><i class="fas fa-times"></i></a>';
?><?php
echo '<a class="dup" href="'.$current.'&filter_brand='.$name_slug.'">'.$name.'</a> <span class="count">(' .count($XXXXXXX). ')</span>';
?></li>
<?php
endif;?>
<?php endwhile;?>
</ul>
</div>
<?php else :?>
<p>Nothing to see</p>
<?php endif; ?>
<style>
li.woocommerce-widget-layered-nav-list__item.wc-layered-nav-term a.remover {
display:none;
}
li.woocommerce-widget-layered-nav-list__item.wc-layered-nav-term a.remover.shown {
display:inline-block;
}
li.woocommerce-widget-layered-nav-list__item.wc-layered-nav-term.hidden
{
display:none;
}
.x-sidebar .widget ul li {
border-top: 1px solid rgba(0,0,0,0.085) !important;
}
ul.woocommerce-widget-layered-nav-list
{
border-top: 1px solid rgba(0,0,0,0.085) !important;
border-bottom: 1px solid rgba(0,0,0,0.085) !important;
}
.woocommerce-widget-layered-nav-list, li.woocommerce-widget-layered-nav-list__item.wc-layered-nav-term {
margin-left:0 !important;
}
.x-sidebar .widget ul li a {
padding-top: 8px;
padding-bottom: 8px;
}
div#woocommerce_layered_nav-3 {
margin: 0;
}
a.remover.shown i {
text-decoration: underline !important;
margin-right:0.5em;
}
</style>
I've changed my approach and edited the get_related_author fucntion, but its only bringing in 1 post can someone see where I'm going wrong?
function get_related_author_posts() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID,
'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
foreach ( $authors_posts as $authors_post ) {
$output = '<div class="listio"><ul><li> <div class="author-post">';
$output .= '<div style="background: url(<?php echo $src[0]; ?> ) !important;
width: 80px; height: 50px; float: left; margin-right: 13px;
background-size: 80px 50px!important; background-color: pink;"></div>';
$output .= '<a href="' . get_permalink( $authors_post->ID ) . '">' .
apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) .
'</a>';
$output .= '</div></li></ul></div>';
}
return $output;
}
There you go:
function get_author_related_posts($author_id, $excluded_post){
global $wpdb;
$author_posts = $wpdb->get_results(
"
SELECT post_author, ID
FROM $wpdb->posts
WHERE post_author = '$author_id' and ID != '$excluded_post'
ORDER BY ID DESC
"
);
return $author_posts;
}
How do i share my website content to wordpress blog and google's blogger like facebook share, twitter share, without any third party tool.
Thanks
Step 1:
Go to your theme’s function.php file and paste below code. This will add sharing button at the bottom of the post
function crunchify_social_sharing_buttons($content) {
if(is_singular() || is_home()){
// Get current page URL
$crunchifyURL = get_permalink();
// Get current page title
$crunchifyTitle = str_replace( ' ', '%20', get_the_title());
// Get Post Thumbnail for pinterest
$crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
$googleURL = 'https://plus.google.com/share?url='.$crunchifyURL;
$bufferURL = 'https://bufferapp.com/add?url='.$crunchifyURL.'&text='.$crunchifyTitle;
// Based on popular demand added Pinterest too
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle;
// Add sharing button at the end of page/page content
$content .= '<div class="crunchify-social">';
$content .= '<h5>SHARE ON</h5> <a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
$content .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
$content .= '<a class="crunchify-link crunchify-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
$content .= '<a class="crunchify-link crunchify-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
$content .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" target="_blank">Pin It</a>';
$content .= '</div>';
return $content;
}else{
// if not a post/page then don't include sharing button
return $content;
}
};
add_filter( 'the_content', 'crunchify_social_sharing_buttons');
Step 2:
Open style.css file of your WordPress theme and put below code for better styling.
.crunchify-link {
padding: 4px 8px 6px 8px;
color: white;
font-size: 12px;
border-radius: 2px;
margin-right: 2px;
cursor: pointer;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
-moz-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
-webkit-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
}
.crunchify-link:hover,.crunchify-link:active {
color: white;
}
.crunchify-twitter {
background: #00aced;
}
.crunchify-twitter:hover,.crunchify-twitter:active {
background: #0084b4;
}
.crunchify-facebook {
background: #3B5997;
}
.crunchify-facebook:hover,.crunchify-facebook:active {
background: #2d4372;
}
.crunchify-googleplus {
background: #D64937;
}
.crunchify-googleplus:hover,.crunchify-googleplus:active {
background: #b53525;
}
.crunchify-buffer {
background: #444;
}
.crunchify-buffer:hover,.crunchify-buffer:active {
background: #222;
}
.crunchify-pinterest {
background: #bd081c;
}
.crunchify-pinterest:hover,.crunchify-pinterest:active {
background: #bd081c;
}
.crunchify-social {
margin: 20px 0px 25px 0px;
-webkit-font-smoothing: antialiased;
font-size: 12px;
}
If you want to show Sharing button at the top of the post then use this code:
function crunchify_social_sharing_buttons($content) {
if(is_singular() || is_home()){
// Get current page URL
$crunchifyURL = get_permalink();
// Get current page title
$crunchifyTitle = str_replace( ' ', '%20', get_the_title());
// Get Post Thumbnail for pinterest
$crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
$googleURL = 'https://plus.google.com/share?url='.$crunchifyURL;
$bufferURL = 'https://bufferapp.com/add?url='.$crunchifyURL.'&text='.$crunchifyTitle;
// Based on popular demand added Pinterest too
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle;
// Add sharing button at the end of page/page content
$variable .= '<div class="crunchify-social">';
$variable .= '<a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
$variable .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
$variable .= '<a class="crunchify-link crunchify-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
$variable .= '<a class="crunchify-link crunchify-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
$variable .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" target="_blank">Pin It</a>';
$variable .= '</div>';
return $variable.$content;
}else{
// if not a post/page then don't include sharing button
return $variable.$content;
}
};
add_filter( 'the_content', 'crunchify_social_sharing_buttons');
Take a look here