How to apply human_time to get_the_modified_time? - wordpress

I am using this variable and it works correctly:
echo '<i class="fa fa-clock"></i> ' . str_replace('', '', human_time_diff( get_the_time('G'), current_time('timestamp') ) . '');
But now I need to make it work by changing get_the_time to get_the_modified_time and it doesn't work, it shows me a result from 50 years ago
Can anyone help me please?

I got what I needed.
I add it in this answer in case someone needs it:
<?php
$lastmodified = get_the_modified_time('U');
$posted = get_the_time('U');
if ($lastmodified > $posted) {
echo "Posted: " . human_time_diff($lastmodified,current_time('U')) . "";
} else {
echo 'Edited: ' . str_replace('', '', human_time_diff( get_the_time('G'), current_time('timestamp') ) . '');
}
?>

Related

Which selector would I use in CSS to make a Buddypress users profile image round?

I am using the BuddyPress, woo-commerce and WC vendors plugins to build my latest WordPress project.
For each of my vendors I wanted their Buddypress profile pictures displayed on each of their products listed for sale so I added the following code to my functions.php file:
function change_wcvendors_cart_sold_by_meta_template( $meta_html, $product_id, $vendor_id ) {
if( ! $vendor_id ) {
return $meta_html;
}
if( ! class_exists( 'WCV_Vendors' ) || ! function_exists( 'bbp_get_user_profile_url' ) ) {
return $meta_html;
}
$profile_url = bbp_get_user_profile_url( $vendor_id );
$profile_name = WCV_Vendors::is_vendor( $vendor_id ) ? WCV_Vendors::get_vendor_sold_by( $vendor_id ) : bp_core_get_user_displayname( $vendor_id );
$profile_image = bp_core_fetch_avatar( 'html=false&item_id=' . $vendor_id );
$meta_html = '%1$s %2$s <a href="' . $profile_url . '" class="no-lightbox vendor-bp-link">
<img src="' . $profile_image . '" class="avatar user-' . $vendor_id . '-avatar avatar-50 photo" alt="Profile picture" width="45" height="45">
' . $profile_name . '
</a>';
return $meta_html;
}
...and it worked and is now showing the user's BP profile image next to their username, next to the "sold by" text, please see here:
https://prnt.sc/s9paz8
But I was just wondering if it was possible to also make the image round using CSS? I have tried using the following code in the custom CSS section to make the image circle but it did not work so I think I am using the wrong selector:
. $profile_image {
border-radius: 50px;
}
Could anybody advise what the correct selector would be to use for selecting the BP profile image, this is how it looks when I inspect element using google chrome:
https://prnt.sc/s9pf8u
https://prnt.sc/s9pgat
Thank you in advance,
you can use the CSS property border-radius to make your images round. I've found this js fiddle for you take a look.
http://jsfiddle.net/2QyY3/2/
Edit: Here's the demo code from your question:
function change_wcvendors_cart_sold_by_meta_template( $meta_html, $product_id, $vendor_id ) {
if( ! $vendor_id ) {
return $meta_html;
}
if( ! class_exists( 'WCV_Vendors' ) || ! function_exists( 'bbp_get_user_profile_url' ) ) {
return $meta_html;
}
$profile_url = bbp_get_user_profile_url( $vendor_id );
$profile_name = WCV_Vendors::is_vendor( $vendor_id ) ? WCV_Vendors::get_vendor_sold_by( $vendor_id ) : bp_core_get_user_displayname( $vendor_id );
$profile_image = bp_core_fetch_avatar( 'html=false&item_id=' . $vendor_id );
$meta_html = '%1$s %2$s <a href="' . $profile_url . '" class="no-lightbox vendor-bp-link">
<img src="' . $profile_image . '" class="round-image avatar user-' . $vendor_id . '-avatar avatar-50 photo" alt="Profile picture" width="45" height="45">
' . $profile_name . '
</a>';
return $meta_html;
}
CSS:
.round-image{
border-radius: 50%;
}

WordPress - Overwriting a template plugin Shortcode

I'm new to php and wordpress.
When I edit an icon box from the theme in the admin panel, i have a few fields, like "title" and "content". The title is inside <h4> </h4> and content is inside <p>
</p>
I need to add another <p style='iconbox_price'></p> after the content, so i can edit it in the admin panel.
This is the code for the iconbox. How can i add this to it, so it would work out.
<?php
function easyweb_webnus_iconbox( $attributes, $content = null ) {
extract(shortcode_atts(array(
"type"=>'',
'icon_title'=>'',
'icon_link_url'=>'',
'icon_link_text'=>'',
"icon_name"=>'',
"iconbox_content"=>'',
"icon_size"=>'',
"icon_color"=>'',
"title_color"=>'',
"content_color"=>'',
"link_color"=>'',
"icon_image"=>'',
"featured"=>'',
"border_left"=>'',
"border_right"=>'',
), $attributes));
ob_start();
$type = ( $type == 0 ) ? '' : $type ;
$iconbox_style = $type17_start_wrap = $type17_end_wrap = '';
if ( $type==17 ) {
$iconbox_style = ( !empty($icon_color) ) ? ' style="color: ' . esc_attr($icon_color) . '"' : '' ;
$type17_start_wrap = '<div class="icon-wrap" style="background-color:' . esc_attr($icon_color) . '">';
$type17_end_wrap = '</div>';
}
$iconbox22_class = '';
if ( $type == 22 ) {
$iconbox22_class .= $featured ? ' ' . $featured : '';
$iconbox22_class .= $border_left ? ' ' . $border_left : '';
$iconbox22_class .= $border_right ? ' ' . $border_right : '';
}
echo '<article class="icon-box' . $type . $iconbox22_class . '" ' . $iconbox_style . '>';
if(!empty($icon_name) && $icon_name != 'none') :
if(!empty($icon_link_url))
echo '' . $type17_start_wrap . '' . do_shortcode( "[icon name='$icon_name' size='$icon_size' color='$icon_color']" ).'' . $type17_end_wrap . '';
else
echo $type17_start_wrap . do_shortcode( "[icon name='$icon_name' size='$icon_size' color='$icon_color']" ) . $type17_end_wrap;
elseif(!empty($icon_image)) :
if(is_numeric($icon_image)){
$icon_image = wp_get_attachment_url( $icon_image );
}
if(!empty($icon_link_url))
echo "<a href='$icon_link_url'>" . '<img src="'.$icon_image.'" alt="" />' . '</a>' ;
else
echo '<img src="'.$icon_image.'" alt="" />';
endif;
$title_style = !empty($title_color)?' style="color:'.$title_color.'"':'';
echo '<h4'.$title_style.'>' . $icon_title . '</h4>';
$content_style = !empty($content_color)?' style="color:'.$content_color.'"':'';
echo '<p'.$content_style.'>'.$iconbox_content .'</p>' ;
$link_style = !empty($link_color)?' style="color:'.$link_color.'"':'';
echo (!empty($icon_link_url) && (!empty($icon_link_text)) )?"<a".$link_style." class=\"magicmore\" href=\"{$icon_link_url}\">{$icon_link_text}</a>":'';
echo '</article>';
$out = ob_get_contents();
ob_end_clean();
$out = str_replace('<p></p>','',$out);
return $out;
}
add_shortcode('iconbox', 'easyweb_webnus_iconbox');
In html this is the code, that is generated:
<article class="icon-box14">
<a href="/razrabotka-saitov/">
<i class="sl-screen-desktop" style=" font-size:42px;"></i>
</a>
<h4 style="height: 22px;">Title</h4>
<p style="height: 116px;">Content<br></p>
<a class="magicmore" href="#">More</a>
</article>
You see the line there:
echo '<p'.$content_style.'>'.$iconbox_content .'</p>' ;
You can add your custom paragraph to that line:
echo '<p'.$content_style.'>'.$iconbox_content .'</p>
<p style='iconbox_price'></p>' ;
I found the solution in my case. Maybe it will help somebody else. I had to edit two files. In my case this is where the first file was located.
wp-content/plugins/'theme'-shortcodes/shortcodes/iconbox.php
I tried to look for where comes the variable $iconbox_content and found it in getting extracted in the code above from an array at this point:
extract(shortcode_atts(array(
"type"=>'',
'icon_title'=>'',
'icon_link_url'=>'',
'icon_link_text'=>'',
"icon_name"=>'',
"iconbox_content"=>'',
"icon_size"=>'',
"icon_color"=>'',
"title_color"=>'',
"content_color"=>'',
"link_color"=>'',
"icon_image"=>'',
"featured"=>'',
"border_left"=>'',
"border_right"=>'',
), $attributes));
So i searched through all the wordpress directory files, because i did not even have an idea where can i find it.
And found it in the themes => 'my theme' => 'my theme' => visualcomposer => shortcodes directory as 03-iconbox.php
I had there different arrays such as this:
array(
"type"=>'textarea',
"heading"=>esc_html__('Content', 'ew'),
"param_name"=> "iconbox_content",
"value"=>"",
"description" => esc_html__( "IconBox Content Goes Here", 'ew')
),
So i guess, the other half of what i did is very logical already, but here it is anyway:
I added an array in this file:
array(
"type"=>'textarea',
"heading"=>esc_html__('Price', 'ew'),
"param_name"=> "iconbox_price",
"value"=>"",
"description" => esc_html__( "Price goes here", 'ew')
),
And in the first file:
To extract "iconbox_price" =>'',
And lower: echo '<p class="iconbox_price">'.$iconbox_price .'</p>' ;
Wish that this helps someone!

Wordpress: Stripping Images of <p> tag and adding <div> IF image has no caption

I've seen some variations of this question around, but I've as of yet been unable to tweak them into what I'm looking for.
In a Wordpress post, if an image is uploaded with a caption the image will be output wrapped in a div (with class wp-caption). Perfect.
However, if there is no caption the image is wrapped in a paragraph tag. I'd like to replace this with a div.
So if an image is uploaded without a caption, it is wrapped in a div as well — something like class="wp-nocaption".
My first try was to modify the media.php file. I changed this section:
if ( 1 > (int) $width || empty($caption) )
return $content;
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align)
. '" style="width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
to this:
if ( 1 > (int) $width || empty($caption) )
return '<div ' . $id . 'class="wp-nocaption ' . esc_attr($align)
. '" style="width: ' . ($width) . 'px">'
. do_shortcode( $content ) . '</div>';
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align)
. '" style="width: ' . ($width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
Which I hoped would do the same thing for a non-captioned image as a captioned one, except the div would have a different class.
But that didn't work. Does anyone have any idea why?
I also found some articles suggesting using a preg_replace function.
http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/
https://wordpress.stackexchange.com/questions/7090/stop-wordpress-wrapping-images-in-a-p-tag
I tweaked their functions, attempting to replace paragraph tags that wrap an image wrapped in a link with div tags.
function filter_ptags_on_images($content) {
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU',
'/<div class="wp-nocaption">\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/div>/iU',
$content);
}
add_filter('the_content', 'filter_ptags_on_images');
But this doesn't work. I've been reading a lot but still can't wrap my head around the php concept of "backreference". I know the replace section of my function is wrong, but I'm not sure how to fix it.
If you have any suggestions as to what I'm doing wrong on either way would be very much appreciated!
Thank you so much!!

I am facing hurdles for changing the layout of simple email form module how do customize layout of this?

// uses $this->_labelAlign, $this->_col2space, $this->_errorTxtColor, $this->_field, $this->_maxFields
// if $this->_field[$x]['rows'] > 0 assumes text area
public function formatRow ()
{
$output = '';
for ($x = 1; $x <= $this->_maxFields; $x++)
{
if ($this->_field[$x]['active'] == 'Y' || $this->_field[$x]['active'] == 'R') {
$name = 'mod_simpleemailform_field' . $x . '_' . $this->_instance;
$value = (isset($_POST[$name])) ? htmlspecialchars($_POST[$name]) : '';
// prevents Joomla from reformatting using javascript
if (strpos($value, '#')) {
$value = str_replace('#', '#', $value);
}
// 2011-12-03 DB: added CSS classes for input, table, row, th and td
$row = '';
$row .= '<tr' . $this->_trClass . '>';
// labels
$row .= "<th" . $this->_thClass . " align='" . $this->_labelAlign . "'>" . $this->_field[$x]['label'] . "</th>";
// space between cols
$row .= "<td" . $this->_spaceClass . " width='" . $this->_col2space . "'> </td>";
// input field
$row .= "<td" . $this->_tdClass . ">";
// check to see if text area
if ($this->_field[$x]['rows'] > 0) {
$row .= sprintf('<textarea name="%s" id="%s" rows="%d" cols="%d" %s>%s</textarea>',
$name,
$name,
$this->_field[$x]['rows'],
$this->_field[$x]['cols'],
$this->_inputClass,
$value);
} else {
$row .= sprintf('<input type="text" name="%s" id="%s" size="%d" value="%s" maxlength="%d" %s/>',
$name,
$name,
$this->_field[$x]['size'],
$value,
$this->_field[$x]['maxx'],
$this->_inputClass);
}
$row .= ($this->_field[$x]['error'])
? $this->formatErrorMessage($this->_errorTxtColor, $this->_field[$x]['error'])
: '';
$row .= "</td>";
$row .= "</tr>\n";
$output .= $row;
}
}
return $output;
}
This is my module code for the output which shows in table format and i don't want this type of layout as a output... I had also try to do changes with tr, td and th tag but faild to get proper out... so please if anyone help me with this.
Wrong format output what i am getting
Correct format output what i want
Ok, here goes. You have a series of
label
spacer...
input field
So replace the table with a
<div class='form-x'
and set its width as you need in the css, i.e.
div.form-x {width:450px; padding:12px;}
Then you want to replace the cells: the first th will become a label, the first td will be dropped altogther, the second will retain only its content (i.e. input or textarea).
To make your life easier, group each couple label-input within a div so:
<div class='formelement'>
<label for='element-1'><?php echo $this->_labelAlign ?></label>
<input ... or <textarea...
</div>
and in the css
div.formelement {padding:20px 0 0 0}
div.formelement label {display:block;}
div.formelement input, div.formelement textarea {width:100%}
Finally the submit button should be placed in a div with
div.submitbutton {text-align:center}
Regarding styling the input type=file, forget it. It's rendered differently by each browser, there are workarounds though but that's a different story.

how to remove read more when full text is on in wordpress?

the code looks like this
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');
there is an option in wp-admin>settings>reading>For each article in a feed, show
if this is set to full text
the excerpt() must return full length article instead of specified length.
how to do this?
Good question! The answer is simple: write your own function!
Open up functions.php in your favorite editor and mash random buttons on your keyboard until you get something like this:
function my_awesome_excerpt ($post_id = false, $full = false, $length = 22) {
if (!$post_id) global $post;
else $post = get_post($post_id);
$text = $post->post_content;
if ($full) return $text;
else {
$text_array = explode(' ', $text);
$return_string = array();
for ($i = 0; $i <= $length; $i++)
array_push($return_string, $text_array[$i]);
$new_awesome_string = '<p>';
$new_awesome_string .= implode(' ', $return_string);
$new_awesome_string .= '</p><p class="readmore">';
$new_awesome_string .= '<a href="' . get_permalink($post_id) . '">';
$new_awesome_string .= 'Read More' . '</a></p>';
return $new_awesome_string;
}
}
Now, you're ready for the cool part. Once you're in your loop, you can write out some magic like this:
echo my_awesome_excerpt();
and it will automagically spit out an excerpt. It's using the global post variable and everything! You can even use it outside of the loop:
echo my_awesome_excerpt($cpt->ID, 22);
and set your own special length!
Or maybe you just know in your heart that it's not worth it, you just want to show the whole thing. How's that look?
Inside the loop, you're going to have to give it a post ID, sorry about that.
echo my_awesome_script($post->ID, false);
I hope this helps. Have a great day!

Resources