Foreach not displaying multiple contents - php

I have a little problem in my Shortcode which I am creating for WordPress. The foreach loop is not displaying multiple posts each time. I'm not sure why is it doing this because if I var_dump the $post variable it shows that both the posts are available to that variable, can someone help me out please?
CODE:
function notes_shortcode($atts) {
global $post;
$atts = shortcode_atts( array( 'category' => $args["category"]), $atts, 'notes' );
$args = array( 'category_name' => $atts["category"]);
$posts = get_posts( $args );
$date = get_the_date( 'd', $post->ID );
$month = get_the_date( 'M', $post->ID );
foreach( $posts as $post ) {
setup_postdata($post);
$imgURL = getpostImage( $post->ID );
$title = get_the_title( $post->ID );
$content = substr(get_the_content() , 0, 125);
$post = '<div class="animated fadeInUp" data-animation="fadeInUp" data-delay="200" style="opacity: 0;">';
$post .= '<div class="col-md-4 bloglist">';
$post .= '<div class="post-content">';
$post .= '<div class="post-image">';
$post .= '<div class="flexslider blog-slider">';
$post .= '<div class="overlay" style="opacity: 0;"></div>';
$post .= '<div class="flex-viewport" style="overflow: hidden; position: relative;">';
$post .= '<ul class="slides" style="width: 800%; -webkit-transition: 0s; transition: 0s; -webkit-transform: translate3d(-350px, 0px, 0px);">';
$post .= '<li class="clone" aria-hidden="true" style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"> </li>';
$post .= '<li class="flex-active-slide" style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"> </li>';
$post .= '<li style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"> </li>';
$post .= '<li class="clone" aria-hidden="true" style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"></li>';
$post .= '</ul></div></div></div>';
$post .= '<div class="date-box"><span class="day">' . $date . '</span>';
$post .= '<span class="month">' . $month . '</span> </div>';
$post .= '<div class="post-text">';
$post .= '<h3>' . $title . '</h3>';
$post .= '<p> ' . $content . '<br>';
$post .= ' Read More</p></div></div></div></div>';
return $post;
}
}
add_shortcode( 'notes', 'notes_shortcode' );
function getpostImage($postid) {
if (has_post_thumbnail($post->ID)){
$imgArray = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID), 'thumbnail' );
$imgURL = $imgArray[0];
return $imgURL;
}
}
Thanks ..

Okay, I solved the problem. I used the WordPress Filters to hook the $buff variable and returned it outside the loop, below is the solution if anyone needs it.
function notes_shortcode($atts) {
global $post;
global $buf;
$atts = shortcode_atts( array( 'category' => $args["category"], 'posts_per_page' => $args["posts_per_page"]), $atts, 'notes' );
$args = array( 'category_name' => $atts["category"], 'posts_per_page' => $atts["posts_per_page"] );
$posts = get_posts( $args );
$date = get_the_date( 'd', $post->ID );
$month = get_the_date( 'M', $post->ID );
$buf = '';
$postHolder = array();
foreach( $posts as $post ) {
setup_postdata($post);
$imgURL = getpostImage( $post->ID );
$title = get_the_title( $post->ID );
$content = substr(get_the_content() , 0, 125);
$buf .= '<div class="animated fadeInUp" data-animation="fadeInUp" data-delay="200" style="opacity: 0;">';
$buf .= '<div class="col-md-4 bloglist">';
$buf .= '<div class="post-content">';
$buf .= '<div class="post-image">';
$buf .= '<div class="flexslider blog-slider">';
$buf .= '<div class="overlay" style="opacity: 0;"></div>';
$buf .= '<div class="flex-viewport" style="overflow: hidden; position: relative; max-width: 350px; max-height: 175px; padding-bottom: 15px; margin-bottom: 15px;">';
$buf .= '<ul class="slides" style="width: 800%; -webkit-transition: 0s; transition: 0s; -webkit-transform: translate3d(-350px, 0px, 0px);">';
$buf .= '<li class="clone" aria-hidden="true" style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"> </li>';
$buf .= '<li class="flex-active-slide" style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"> </li>';
$buf .= '<li style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"> </li>';
$buf .= '<li class="clone" aria-hidden="true" style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"></li>';
$buf .= '</ul></div></div></div>';
$buf .= '<div class="date-box"><span class="day">' . $date . '</span>';
$buf .= '<span class="month">' . $month . '</span> </div>';
$buf .= '<div class="post-text">';
$buf .= '<h3>' . $title . '</h3>';
$buf .= '<p> ' . $content . '<br>';
$buf .= ' Read More</p></div></div></div>';
$buf .= apply_filters( 'post_class', '</div>', $atts );
}
$buf .= apply_filters( 'post_class', '', $atts );
return $buf;
}
add_shortcode( 'notes', 'notes_shortcode' );
function getpostImage($postid) {
if (has_post_thumbnail($post->ID)){
$imgArray = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID), 'thumbnail' );
$imgURL = $imgArray[0];
return $imgURL;
}
}
Thankyou all for the help ..

You are returning the function, that means that your are making the function end. What you can do is send the array and then loop it later.Use the code below
function notes_shortcode($atts) {
global $post;
$atts = shortcode_atts( array( 'category' => $args["category"]), $atts, 'notes' );
$args = array( 'category_name' => $atts["category"]);
$posts = get_posts( $args );
$date = get_the_date( 'd', $post->ID );
$month = get_the_date( 'M', $post->ID );
$array = array();
foreach( $posts as $post ) {
setup_postdata($post);
$imgURL = getpostImage( $post->ID );
$title = get_the_title( $post->ID );
$content = substr(get_the_content() , 0, 125);
$post = '<div class="animated fadeInUp" data-animation="fadeInUp" data-delay="200" style="opacity: 0;">';
$post .= '<div class="col-md-4 bloglist">';
$post .= '<div class="post-content">';
$post .= '<div class="post-image">';
$post .= '<div class="flexslider blog-slider">';
$post .= '<div class="overlay" style="opacity: 0;"></div>';
$post .= '<div class="flex-viewport" style="overflow: hidden; position: relative;">';
$post .= '<ul class="slides" style="width: 800%; -webkit-transition: 0s; transition: 0s; -webkit-transform: translate3d(-350px, 0px, 0px);">';
$post .= '<li class="clone" aria-hidden="true" style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"> </li>';
$post .= '<li class="flex-active-slide" style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"> </li>';
$post .= '<li style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"> </li>';
$post .= '<li class="clone" aria-hidden="true" style="width: 350px; float: left; display: block;"> <img src="' . $imgURL . '" alt="" draggable="false"></li>';
$post .= '</ul></div></div></div>';
$post .= '<div class="date-box"><span class="day">' . $date . '</span>';
$post .= '<span class="month">' . $month . '</span> </div>';
$post .= '<div class="post-text">';
$post .= '<h3>' . $title . '</h3>';
$post .= '<p> ' . $content . '<br>';
$post .= ' Read More</p></div></div></div></div>';
$array[] = $post;
}
return $array;
}
add_shortcode( 'notes', 'notes_shortcode' );
function getpostImage($postid) {
if (has_post_thumbnail($post->ID)){
$imgArray = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID), 'thumbnail' );
$imgURL = $imgArray[0];
return $imgURL;
}
}
Hope this helps you

Related

wordpress notification section wp_post all data face but how to image is not display|How to display image wp_post image

See Issue Image Here
function demo1(){
$args = array(
'public' => true,
'_builtin' => false
);
$post_types = get_post_types( $args );
$post_types['post'] = ''; // default = 'and'
here is my code facing issue wp_post guide Image not facing how to display image give me some idea
foreach ( $post_types as $post_type ) {
echo '<p>' . $post_type . '</p>';
for ($x=0; $x<=0; $x++){
$args = array( 'numberposts' => $x, 'post_type' => $post_type); // replace n with the number of posts
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
?>
<div style="border: 1px solid; text-decoration: none; padding:10px 0px 10px 20px; ">
<?php
echo '<a href="' . get_permalink($recent["ID"]) .'" >'."<h3 style='text-decoration: none;color:#000000'>" .$recent["post_title"] . "</h3>". '</a>';
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['post_title'] ).'" height="200" width="200"/>'.'<br>';
// echo '<img src='. get_permalink($recent["ID"]) .'>'.$recent["guid"].'</br>';
echo '<i href="' . get_permalink($recent["ID"]) .'" >' .$recent["post_modified"] . '</i></br>';
?>
</div>
<?php
}
}
}
}

increment id for dynamically generated div

I want to dynamically generate video player container divs that will have a unique id. The elements are generated through Visual Composer in WordPress and the final html should look something like this:
<div style="width: 100%; display: inline-block; position: relative;">
<div style="margin-top: '. $custom_margin .'"></div>
<div id="player_1" style="position:absolute;top:0;left:0;right:0;bottom:0"></div>
</div>
<div style="width: 100%; display: inline-block; position: relative;">
<div style="margin-top: '. $custom_margin .'"></div>
<div id="player_2" style="position:absolute;top:0;left:0;right:0;bottom:0"></div>
</div>
<div style="width: 100%; display: inline-block; position: relative;">
<div style="margin-top: '. $custom_margin .'"></div>
<div id="player_3" style="position:absolute;top:0;left:0;right:0;bottom:0"></div>
</div>
The user should be able to add as many div elements with unique ids as he likes. This is how my php looks right now:
EDIT: The function is called for every single video container
public function vc_custvideo_html($atts){
extract(
shortcode_atts(
array(
'custom_width' => '',
'custom_height' => '',
),
$atts
)
);
$percent = $custom_height / $custom_width;
$custom_margin = number_format( $percent * 100, 2 ) . '%';
$html = '';
$html.= '<div style="width: 100%; display: inline-block; position: relative;">';
$html.= '<div style="margin-top: '. $custom_margin .'"></div>';
$html.= '<div id="player_" style="position:absolute;top:0;left:0;right:0;bottom:0"></div>';
$html.= '</div>';
return $html;
}
I can understand that i have to use a foreach loop to generate the unique ids but i'm really new at php and I need help.
Something like that
$i = 0;
foreach ($playerInstance as $k => $currPlayer {
vc_custvideo_html($currPlayer, $i)
$i++;
}
public function vc_custvideo_html($atts, $index){
extract(
shortcode_atts(
array(
'custom_width' => '',
'custom_height' => '',
),
$atts
)
);
$percent = $custom_height / $custom_width;
$custom_margin = number_format( $percent * 100, 2 ) . '%';
$html = '';
$html.= '<div style="width: 100%; display: inline-block; position: relative;">';
$html.= '<div style="margin-top: '. $custom_margin .'"></div>';
$html.= '<div id="player_'.$index.'" style="position:absolute;top:0;left:0;right:0;bottom:0"></div>';
$html.= '</div>';
return $html;
}
Or with a for loop maybe
Assuming the function is called once per Video, use an outer foreach and a counter:
$counter=1;
foreach($arrayOfVideos as $video){
$this->vc_custvideo_html($video, $counter);
$counter++;
}
And inside your function, just use the $counter variable:
// [...]
$html.= '<div style="margin-top: '. $custom_margin .'"></div>';
$html.= '<div id="player_"' . $counter . ' style="position:absolute;top:0;left:0;right:0;bottom:0"></div>';
$html.= '</div>';

Custom HTML for WordPress Image Gallerys, only outputs half the function

I took the following code from an example and adjusted it so a standard gallery in wordpress would output as a Flexslider and Carousel. I can output one of them just fine, but I added additional *outputs for a Carousel as well, and now only the Carousel prints out. Any help on how I can get the whole thing to output would be appreciated
add_filter('post_gallery', 'my_post_gallery', 10, 2);
function my_post_gallery($output, $attr) {
global $post;
if (isset($attr['orderby'])) {
$attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
if (!$attr['orderby'])
unset($attr['orderby']);
}
extract(shortcode_atts(array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => ''
), $attr));
$id = intval($id);
if ('RAND' == $order) $orderby = 'none';
if (!empty($include)) {
$include = preg_replace('/[^0-9,]+/', '', $include);
$_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
$attachments = array();
foreach ($_attachments as $key => $val) {
$attachments[$val->ID] = $_attachments[$key];
}
}
if (empty($attachments)) return '';
// Here's your actual output, you may customize it to your need
$output = "<div class=\"wordpress-gallery\">\n";
$output = "<div id=\"sliding\" class=\"flexslider flexslider--post-content\">\n";
//$output .= "<div class=\"preloader\"></div>\n";
$output .= "<ul class=\"slides flexslider__slides\">\n";
// Now you loop through each attachment
foreach ($attachments as $id => $attachment) {
// Fetch the thumbnail (or full image, it's up to you)
// $img = wp_get_attachment_image_src($id, 'medium');
// $imgThumbnail = wp_get_attachment_image_src($id, 'thumbnail');
$img = wp_get_attachment_image_src($id, 'full');
$output .= "<li class=\"slide flexslider__slide cover\">\n";
$output .= "<img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"\" />\n";
$output .= "</li>\n";
}
$output .= "</ul>\n";
$output .= "</div>\n";
$output = "<div id=\"carousel\" class=\"flexslider flexslider--post-content-carousel\">\n";
$output .= "<ul class=\"slides flexslider__slides\">\n";
foreach ($attachments as $id => $attachment) {
$imgThumbnail = wp_get_attachment_image_src($id, 'thumbnail');
$output .= "<li >\n";
$output .= "<img src=\"{$imgThumbnail[0]}\" alt=\"\" />\n";
$output .= "</li>\n";
}
$output .= "</ul>\n";
$output .= "</div>\n";
$output .= "</div>\n";
return $output;
}
the html that gets outputed so far (it doesn't output the #sliding div, only the #carousel):
<div id="carousel" class="flexslider flexslider--post-content-carousel">
<div class="flex-viewport" style="overflow: hidden; position: relative;">
<ul class="slides flexslider__slides" style="width: 1400%; transition-duration: 0s; transform: translate3d(0px, 0px, 0px);">
<li class="flex-active-slide" style="width: 210px; float: left; display: block;">
<img src="//localhost:3002/test-site/wp-content/uploads/2016/01/test-image-300x300.jpg" alt="" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="//localhost:3002/test-site/wp-content/uploads/2016/01/test-image-1-300x300.jpg" alt="" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="//localhost:3002/test-site/wp-content/uploads/2016/01/test-image-2-300x300.jpg" alt="" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="//localhost:3002/test-site/wp-content/uploads/2016/01/test-image-3-300x300.jpg" alt="" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="//localhost:3002/test-site/wp-content/uploads/2016/01/test-image-4-300x300.jpg" alt="" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="//localhost:3002/test-site/wp-content/uploads/2016/01/test-image-5-300x300.jpg" alt="" draggable="false">
</li>
<li style="width: 210px; float: left; display: block;">
<img src="//localhost:3002/test-site/wp-content/uploads/2016/01/test-image-6-300x300.jpg" alt="" draggable="false">
</li>
</ul>
</div>
<ul class="flex-direction-nav">
<li class="flex-nav-prev"><a class="flex-prev flex-disabled" href="#" tabindex="-1">Previous</a></li>
<li class="flex-nav-next"><a class="flex-next" href="#">Next</a></li>
</ul>
</div>
You have a few errors, that I can see.
// Here's your actual output, you may customize it to your need
$output = "<div class=\"wordpress-gallery\">\n";
$output = "<div id=\"sliding\" class=\"flexslider flexslider--post-content\">\n";
If you wish to append data, you need to put a period . before your equals = like this .= on the second $output assignment. Anytime you are appending but not putting .= after the variable name, you are basically reassigning it a new value instead of adding to it.
Also change this line:
$output = "<div id=\"carousel\" class=\"flexslider flexslider--post-content-carousel\">\n";
to:
$output .= "<div id=\"carousel\" class=\"flexslider flexslider--post-content-carousel\">\n";
The problem lies in the fact that you were basically resetting the variable with a new output instead of appending the data to it.
Hope this helps you.
Be sure to go through your code and double check variable assignments to make sure you are appending rather than resetting.
You have two errors in your code, that lies in following lines:
$output = "<div id=\"sliding\" class=\"flexslider flexslider--post-content\">\n";
[...]
$output = "<div id=\"carousel\" class=\"flexslider flexslider--post-content-carousel\">\n";
You are resetting $output variable two times, thus what was written to it before is lost, so you should replace them with:
$output .= "<div id=\"sliding\" class=\"flexslider flexslider--post-content\">\n";
[...]
$output .= "<div id=\"carousel\" class=\"flexslider flexslider--post-content-carousel\">\n";

How do I display the social button where I want?

I don't want it to display in the_content. With the_content, it adds a p tag, and i don't want that. I want it display in woocommerce_share hook. How do I do that?
when I try add_action or add_filter code , it doesn't work. I just want to display it in woocommerce product page and my custom post type "Journals"
My custom post type is a blog post. When the user click the post, in the post I want the social icons to show up.
add_filter( 'IS_THERE_A_CUSTOM_FILTER_I_CAN_USE_WITHOUT_THE_P_TAG', 'crunchify_social_sharing_buttons');
add_action( 'woocommerce_share', 'crunchify_social_sharing_buttons');
functions.php
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');
style.css
.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;
}
add_filter( 'IS_THERE_A_CUSTOM_FILTER_I_CAN_USE_WITHOUT_THE_P_TAG', 'crunchify_social_sharing_buttons');
No, there is not. Anything that is added via the the_content filter is ultimately displayed as:
apply_filters( 'the_content', $content );
And the filters that are applied include wpautop(). Your crunchify_social_sharing_buttons function that is filtering the content filter is returning a value. To display the buttons from your custom function on the woocommerce_share hook you would need to echo the value.
add_action( 'woocommerce_share', 'crunchify_social_sharing_buttons');
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>';
echo $content;
}
}
This works, but for my social-bar.php code I remove the $value in add_filter. I'm not sure if that is the right way to do it. Because I don't to print any value. Can someone correct me if this is the right way to do it. Thanks
echo apply_filters( 'social_bar');
FUNCTION.php
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');
add_filter( 'social_bar', 'crunchify_social_sharing_buttons');
social-bar.php
<!-- socialbar-->
<?php
echo apply_filters( 'social_bar');
?>
<!-- /socialbar-->
Display the social bar where I want
<?php
get_template_part('socialbar');
?>

PHP Change default value for Select list

I have this little issue with the price form for my Joomla backend.
The default value is always "nothing", so I just need to set "Euro" as default (see screenshot).
I'm pretty newbie with PHP, so I can't do it by myself..
Here is the part of code that realizes this form:
$htmlPrice = '<div class="jomcomdevPriceRow">';
$htmlPrice .= '<div class="control-group" style="float: left; margin-right: 10px;">';
$htmlPrice .= '<label> '.JText::_('COM_JOMCOMDEV_FIELD_PRICE_NETTO').'</label><input type="text" name="' . $this->name.'[price_netto][]" id="' . $this->id . 'ValueNetto"' . ' value="" />';
$htmlPrice .= '</div>';
$htmlPrice .= '<div class="control-group" style="float: left; margin-right: 10px;">';
$htmlPrice .= str_replace("\n", '', '<label is="jform_featured-lbl"> '.JText::_('COM_JOMCOMDEV_FIELDSET_PRICE_GROUP').'</label>'.JHtml::_('select.genericlist', JHtml::_('jdcategory.options', 'com_jomestate.price', array('onlyroot' => 0)), $this->name.'[type_id][]',"", 'value', 'text', null, true));
$htmlPrice .= '</div>';
$htmlPrice .= '</div>';
I hope I'm clear enough. Thank you in advance.
Screenshot:
http://i.stack.imgur.com/2Ix39.png
UPDATE
Hmm, I don't know really where is configured this element. Here is full code, maybe I'm looking a wrong part..
defined( '_JEXEC' ) or die( 'Restricted access' );
class JFormFieldJdPrice extends JFormField
{
/**
* #var string The form field type.
* #since 11.1
*/
public $type = 'JdAddress';
/**
* Method to get the field input markup.
*
* #return string The field input markup.
*
* #since 11.1
*/
public function getInput()
{
$id = JRequest::getInt('id');
// if(empty($id)) {
// $html = '<div style="padding: 10px; margin: 10px 0;">';
// $html .= JText::_('COM_JOMCOMDEV_PRICEADD_NOID_INFO');
// $html .= '</div>';
// return $html;
// }
$htmlPrice = '<div class="jomcomdevPriceRow">';
$htmlPrice .= '<div class="control-group" style="float: left; margin-right: 10px;">';
$htmlPrice .= '<label> '.JText::_('COM_JOMCOMDEV_FIELD_PRICE_NETTO').'</label><input type="text" name="' . $this->name.'[price_netto][]" id="' . $this->id . 'ValueNetto"' . ' value="" />';
$htmlPrice .= '</div>';
$htmlPrice .= '<div class="control-group" style="float: left; margin-right: 10px;">';
$htmlPrice .= str_replace("\n", '', '<label is="jform_featured-lbl"> '.JText::_('COM_JOMCOMDEV_FIELDSET_PRICE_GROUP').'</label>'.JHtml::_('select.genericlist', JHtml::_('jdcategory.options', 'com_jomestate.price', array('onlyroot' => 0)), $this->name.'[type_id][]',"", 'value', 'text', null, true));
$htmlPrice .= '</div>';
$htmlPrice .= '</div>';
$link = JURI::root()."index.php?option=com_jomcomdev&format=raw&task=ajax.price&name=first&id=";
$runScript = "
window.addEvent('domready', function() {
var options = {htmlPrice: '".$htmlPrice."', link: '".$link."', selector: $$('#".$this->id."')};
Comdev.price.init(options);
});
";
$document = JFactory::getDocument();
$document->addScriptDeclaration($runScript);
JText::script('COM_JOMCOMDEV_JS_BUTTON_ADD');
JText::script('COM_JOMCOMDEV_JS_BUTTON_DELETE');
JText::script('COM_JOMCOMDEV_JS_BUTTON_OPTION');
JText::script('COM_JOMCOMDEV_FIELD_PRICE_NETTO');
$html = '';
$html .= '<div id="'.$this->id.'">';
if(!empty($id)) {
$data = Main_Price::get($id, (string) $this->element['extension']);
foreach($data AS $d) {
$html .= '<div class="jomcomdevPriceRow">';
$html .= '<div class="control-group" style="float: left; margin-right: 10px;">';
$html .= '<label is="jform_featured-lbl"> '.JText::_('COM_JOMCOMDEV_FIELD_PRICE_NETTO').'</label><input type="text" name="' . $this->name.'[price_netto][]" id="' . $this->id . 'ValueNetto"' . ' value="'.$d->price_netto.'" />';
$html .= '</div>';
$html .= '<div class="control-group" style="float: left; margin-right: 10px;">';
$html .= '<label is="jform_featured-lbl"> '.JText::_('COM_JOMCOMDEV_FIELDSET_PRICE_GROUP').'</label>'.JHtml::_('select.genericlist', JHtml::_('jdcategory.options', 'com_jomestate.price', array('onlyroot' => 0)), $this->name.'[type_id][]', 'value', null, 'text', $d->type_id, true);
$html .= '</div>';
$html .= '<div class="control-group" style="padding-top: 17px;">';
$html .= '<label></label>'.JText::_('COM_JOMCOMDEV_JS_BUTTON_DELETE').'';
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="clr"></div>';
}
}
$html .= '</div>';
return $html;
}
}

Categories