This shortcode shows the last X (sorting from the newest to the oldest) posts on my home page. I want to choose which ones I'd like to show by ID. How to do it?
I have a shortcode which looks like this
This is what input:
if(!empty($blog)){
echo do_shortcode('[blog item_number=4]');
}
This is a code of this shortcode.
function beau_blog($atts, $content = null, $code = '')
{
global $imgsize;
extract(shortcode_atts(array(
'post_not_in' => '',
'item_number' => '4',
), $atts));
$loop = new WP_Query('&posts_per_page=' . $item_number);
?>
<section class="beau-blog stretch-layout">
<div class="blog-title"><?php echo get_post_meta(get_the_ID(), '_page_blog_text', TRUE); ?></div>
<div class="blog-content"><?php echo get_post_meta(get_the_ID(), '_page_blog_des', TRUE); ?></div>
<?php if ($loop->have_posts()) : ?>
<div class="blog-lists">
<?php $i = 0;
while ($loop->have_posts()) : $loop->the_post();
$featuredID = wp_get_attachment_image_src(get_post_thumbnail_id(), 'single-post-thumbnail');
$date = strtotime( get_the_date() );
if ($i % 2 != 0) {
?>
<div class="row-fluid">
<div class="span6 blog-odd hover-img beau-animated move-to-right">
<?php beau_resizer($featuredID[0], $imgsize['blog']['w'], $imgsize['blog']['h'], true, get_the_title(get_the_ID())); ?>
</div>
<div class="span6 blog-odd-r beau-animated move-to-left">
<div class="odd-bg"></div>
<div class="content">
<h3><?php the_title(); ?></h3>
<div class="date"><?php echo date( 'l', $date ).' '.date( 'j', $date ).' '.date( 'F ', $date ).' '.date( 'Y ', $date ); ?></div>
<div class="blog-description"><?php echo beau_excerpt(54); ?></div>
</div>
</div>
</div>
<?php
} else {
?>
<div class="row-fluid bg-r">
<div class="span6 blog-even-l beau-animated move-to-right">
<div class="odd-bg"></div>
<div class="content">
<h3><?php the_title(); ?></h3>
<div class="date"><?php echo date( 'l', $date ).' '.date( 'j', $date ).' '.date( 'F ', $date ).' '.date( 'Y ', $date ); ?></div>
<div class="blog-description"><?php echo beau_excerpt(54); ?></div>
</div>
</div>
<div class="span6 blog-odd hover-img beau-animated move-to-left">
--------
<?php beau_resizer($featuredID[0], $imgsize['blog']['w'], $imgsize['blog']['h'], true, get_the_title(get_the_ID())); ?>
----------
</div>
</div>
<?php
}
?>
<?php $i++; endwhile; ?>
</div>
<?php
wp_reset_postdata();
endif;
?>
</section>
<?php
$out = ob_get_contents();
ob_end_clean();
return $out;
}
add_shortcode('blog', 'beau_blog');
function beau_blog_style2($atts, $content = null, $code = '')
{
global $imgsize;
extract(shortcode_atts(array(
'post_not_in' => '',
'item_number' => '4'
), $atts));
$loop = new WP_Query('&posts_per_page=' . $item_number);
?>
<section class="beau-blog stretch-layout style2">
<div class="blog-title"><?php echo get_post_meta(get_the_ID(), '_page_blog_text', TRUE); ?></div>
<?php if ($loop->have_posts()) : ?>
<div class="blog-lists blog-lists-full-layout">
<?php $i = 0;
while ($loop->have_posts()) : $loop->the_post();
$featuredID = wp_get_attachment_image_src(get_post_thumbnail_id(), 'single-post-thumbnail');?>
<div class="row-fluid">
<div class="blog-list-container">
<div class="span12 beau-animated fade-in">
<div class="full-content">
<div class="row-fluid">
<div class="span1">
<div class="date"><span><?php echo get_the_time('d') ?></span></div>
<div class="month-year">
<span><?php echo substr(get_the_time('F'), 0, 3); ?></span></div>
</div>
<div class="span11">
<h3><?php the_title(); ?></h3>
<div class="content style2">
<?php beau_excerpt(30, true); ?>
</div>
</div>
</div>
<div class="row-fluid">
<a href="<?php echo get_permalink() ?>">
<div class="post-thumb hover-img">
<!-- <img src="--><?php //echo $featuredID[0] ?><!--"-->
<!-- alt="--><?php //echo get_the_title(); ?><!--">-->
<?php beau_resizer($featuredID[0], $imgsize['blog2']['w'], $imgsize['blog2']['h'], true, get_the_title()); ?>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
<?php $i++; endwhile;
?>
</div>
<?php
wp_reset_postdata();
endif;
?>
</section>
<?php
$out = ob_get_contents();
ob_end_clean();
return $out;
}
add_shortcode('blog_style2', 'beau_blog_style2');
function beau_attendingform($atts, $content = null, $code = '')
{
?>
<section class="beau-attending-form">
<h2 class="attending-title"><?php echo get_post_meta(get_the_ID(), '_page_attending_text', TRUE); ?></h2>
<div class="attending-content"><?php echo get_post_meta(get_the_ID(), '_page_attending_des', TRUE); ?></div>
<div class="row-fluid">
<?php $rand = uniqid();
ob_start(); ?>
<script type="text/javascript">
jQuery(function ($) {
$('#contact_<?php echo $rand; ?>').submit(function () {
$('#loading_contact_<?php echo $rand; ?>').fadeIn('fast');
$('#result_contact_<?php echo $rand; ?>').hide();
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function (data) {
$('#result_contact_<?php echo $rand; ?>').html(data);
$('#result_contact_<?php echo $rand; ?>').fadeIn('fast');
$('#loading_contact_<?php echo $rand; ?>').hide();
}
})
return false;
});
});
</script>
<form id="contact_<?php echo $rand; ?>"
action="<?php echo BEAU_BASE_URL . '/include/scripts/attending.php'; ?>" method="post"
class="span12 attending">
<!-- <form id="contact_--><?php //echo $rand; ?><!--" action="-->
<?php //echo BEAU_BASE_URL .'/include/scripts/contact.php'; ?><!--" method="post">-->
<input type="text" name="fullname" placeholder="Jak się nazywasz?" class="span12">
<input type="text" name="email" placeholder="Email" class="span12">
<input type="text" name="persons_attending" placeholder="Temat" class="span12">
<textarea class="span12" name="wedding_ceremony" rows="8" placeholder="Tu wpisz wiadomość"></textarea>
<input type="submit" class="btn" name="submit" value="<?php _e('Naciśnij by wysłać', 'beau'); ?>"
id="contact-submit"/>
<input type="hidden" name="send_to" value="<?php echo $send_to; ?>"/>
<!-- I’M ATTENDING-->
<div id="result_contact_<?php echo $rand; ?>"></div>
<div id="loading_contact_<?php echo $rand; ?>" style="margin-bottom: 20px; display: none;"></div>
</form>
</div>
</section>
<?php
$out = ob_get_contents();
ob_end_clean();
return $out;
}
add_shortcode('attendingform', 'beau_attendingform');
function beau_attendingform_style2($atts, $content = null, $code = '')
{
?>
<section class="beau-attending-form style2">
<h2 class="attending-title"><?php echo get_post_meta(get_the_ID(), '_page_attending_text', TRUE); ?></h2>
<div class="row-fluid">
<?php $rand = uniqid();
ob_start(); ?>
<script type="text/javascript">
jQuery(function ($) {
$('#contact_<?php echo $rand; ?>').submit(function () {
$('#loading_contact_<?php echo $rand; ?>').fadeIn('fast');
$('#result_contact_<?php echo $rand; ?>').hide();
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function (data) {
$('#result_contact_<?php echo $rand; ?>').html(data);
$('#result_contact_<?php echo $rand; ?>').fadeIn('fast');
$('#loading_contact_<?php echo $rand; ?>').hide();
}
})
return false;
});
});
</script>
<form id="contact_<?php echo $rand; ?>"
action="<?php echo BEAU_BASE_URL . '/include/scripts/attending.php'; ?>" method="post"
class="span12 attending">
<div class="f-bg"></div>
<div class="f-bg-left-top"></div>
<div class="f-bg-right-top"></div>
<div class="f-bg-left-bottom"></div>
<div class="f-bg-right-bottom"></div>
<input type="text" name="fullname" placeholder="Fullname" class="span12">
<input type="text" name="email" placeholder="Email" class="span12">
<input type="submit" class="btn" name="submit" value="<?php _e('Wysyłam wiadomość!', 'beau'); ?>"
id="contact-submit"/>
<input type="hidden" name="send_to" value="<?php echo $send_to; ?>"/>
<div id="result_contact_<?php echo $rand; ?>"></div>
<div id="loading_contact_<?php echo $rand; ?>" style="margin-bottom: 20px; display: none;"></div>
</form>
</div>
</section>
<?php
$out = ob_get_contents();
ob_end_clean();
return $out;
}
add_shortcode('attendingform_style2', 'beau_attendingform_style2');
function beau_button($atts, $content = null)
{
extract(shortcode_atts(array(
'icon' => '',
'size' => 'small',
'color' => '',
'url' => '#'
), $atts));
$attstoclass = '';
if (!empty($icon)) $attstoclass = '<i class="' . $icon . '"></i>';
$out = '<a class="st-button ' . $size . ' ' . $color . '" href="' . $url . '">' . $attstoclass . strip_tags($content) . '</a>';
return $out;
}
Website is: nikosis.mzonespace.co.uk
change you function beau_blog() as below only the initial few lines other is same as it is
function beau_blog($atts, $content = null, $code = '')
{
global $imgsize;
extract(shortcode_atts(array(
'post_not_in' => '',
'post_in' => '', //you cannoot use post__not_in and post__in in same query so you have to use either one of that. I've modified it to give priority to post_in so if that argument is empty then only the post_not_in ids are used to exclude those posts.
'item_number' => '4',
), $atts));
if(empty($post_in)){
$loop = new WP_Query('&posts_per_page=' . $item_number.'&post__not_in='.$post_not_in);
}
else{
$loop = new WP_Query('&posts_per_page=' . $item_number.'&post__in='.$post_in);
}
?>
.....
Now when you want to show posts of ids 1,2 and 3 only do it as below
echo do_shortcode('[blog item_number=4&post_in=array(1,2,3)]');
please try below code - this is simple sample
function show_posts_by_id( $atts, $content = null, $code ) {
$item_number = 4;
$post_ids = null;
extract(
shortcode_atts(
array(
'post_ids' => '',
'item_number' => 4,
),
$atts
),
EXTR_IF_EXISTS
);
$posts = get_posts(
array(
'post_type' => 'page',
'post__in' => explode( ',', $post_ids ),
'posts_per_page' => (int)$item_number,
'offset' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
)
);
// do what you need
}
add_shortcode( 'show_posts_by_id', 'show_posts_by_id' );
Use shortcode like this: [show_posts_by_id post_ids=12,15,2176 item_number=4]
Related
I am not able to see any changes after editing opencart 2.0.3.1, I am not getting the images and also edited the files from category.php (catlog>controller>product) and category.tpl(catlog>view>theme>*>template>product) and replaced
$data['categories'][] = array(
and
<?php if ($categories) { ?>
with
if ($result['image']) {
$image = $this->model_tool_image- >resize($result['image'], 100, 100);
} else {
$image = $this->model_tool_image- >resize('placeholder.png', 100, 100);
}
$data['categories'][] = array(
'name' => $result['name'] . ($this->config- >get('config_product_count') ? ' (' . $this->model_catalog_product- >getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
'thumb' => $image
);
and
<?php if ($categories) { ?>
<div class="col-sm-12">
<div>
<h3><?php echo $text_refine; ?></h3>
</div>
<div style="text-align: center;">
<div class="row">
<?php foreach ($categories as $category) { ?>
<div class="col-sm-2 col-xs-6" style="margin-bottom: 20px;">
<img src="<?php echo $category['thumb']; ?>" alt="<?php echo $category['name']; ?>" />
<?php echo $category['name']; ?>
</div>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
respectively but not able to get any thing! Help highly appreciated
I'm trying to get further, new Image Links that are loaded to display.
Currently 5 are displayed, but we want to add a sixth & maybe 2 or 3 others in the future.
The issue we are having is when we add the sixth, it overwrites one of the existing 5.
Can anyone help with, what I suspect is the Function, to allow us to add more?
Thanks
HTML
<div class="content">
<div class="visible-xs visible-sm" style="background: #367586;color: white;width: 100%;">
<h2 style="color: white;padding: 20px;text-align: center;">Call us on <a style="text-decoration: none;color: white;" href="tel:0141999999">0131 344 4146</a></h2>
</div>
<div class="pageTitle">
<h1><?php single_cat_title(); ?></h1>
</div>
<?php
$posts = get_posts('category='.$cat);
vvwc_carouselList($posts);
?>
<div class="clearfix"></div>
PHP
function vvwc_carouselList($posts, $postId=null){
if(!empty($posts)){
echo '
<div class="nonCarousel">
<ul class="list-inline">
';
$x = 1;
foreach($posts as $post){
$active = '';
$feature = '';
if($postId == $post->ID){
$active = 'active';
$feature = 'feature';
}
if($x == 5 || $x == 1){
?>
<div class='row'>
<?php
}
echo '
<li class="col-md-3 '.$feature.'">
<div class="'.$active.' carousel-border">
<div class="carousel-item">
<a data-item="'.$post->ID.'" href="'.get_permalink($post->ID).'">
';
if(has_post_thumbnail($post->ID)){
echo get_the_post_thumbnail($post->ID);
}
echo "<div class='camperTitle'>" . strtoupper($post->post_title) . "</div>";
echo '
</a>
</div>
</div>
</li>
';
if($x == 4 || $x == count($posts)+1 ){
?>
</div>
<?php
}
$x ++;
}
echo '
</ul>
<div class="clearfix"></div>
</div>
';
}
echo '
<div class="clearfix"></div>
<script>
jQuery(document).ready(function($){
$(".carousel ul").owlCarousel({
items: 4,
pagination: false,
navigation: true,
navigationText: false,
slideSpeed: 1000,
rewindSpeed: 1000
});
});
</script>
';
}
Found it, I replaced:
$posts = get_posts('category='.$cat);
with
$posts = get_posts(array(
'category' =>15,
'orderby' => 'title',
'posts_per_page'=> 10,
'order' => 'ASC',
));
I've seen lots of questions and answers around how to do this but I am very stuck how I implement this into my webpage. I have a div named "banner" that contains an image drawn from a custom field that is on all my artist pages as a banner for each page. I would like to be able to drag this image inside the div and to save it's position. (I only want this function for myself, not visitors to the website) AKA Facebook page cover image.. This would allow me to add an image that is bigger than the div container to my custom field and for me to edit how this is showing inside the div.
This demonstates what I want to do- http://w3lessons.info/2014/08/31/facebook-style-cover-image-reposition-using-jquery-php/
but i don't understand where i put these codes in my wordpress files and how to make this work for me.. I only want this on my artist pages, and therefore using my single-artists.php template..
Here is my php code-
<?php
// artist download start
// if ( isset($_GET['download']) ) {
// header('Content-type: application/mp3');
// header('Content-Disposition: attachment; filename='.basename($_GET['download']));
// readfile( $_GET['download'] );
// }
// artist download end
get_header();
global $cs_transwitch,$prettyphoto_flag;
$prettyphoto_flag = "true";
$cs_artist = get_post_meta($post->ID, "cs_artist", true);
if ( $cs_artist <> "" ) {
$xmlObject = new SimpleXMLElement($cs_artist);
$cs_layout = $xmlObject->cs_layout;
$cs_sidebar_left = $xmlObject->cs_sidebar_left;
$cs_sidebar_right = $xmlObject->cs_sidebar_right;
}
if ( $cs_layout == "left" ) {
$cs_layout = "two-thirds column right";
$show_sidebar = $cs_sidebar_left;
}
else if ( $cs_layout == "right" ) {
$cs_layout = "two-thirds column left";
$show_sidebar = $cs_sidebar_right;
}
else $cs_layout = "sixteen columns left";
?>
<div id="banner">
<div id="bannercontent"><?php
list($src, $w, $h) = get_custom_field('banner:to_image_array');
?>
<img src="<?php print $src; ?>" width="100%" />
</div></div>
<script>$( "#bannercontent" ).draggable({
stop: function(){
alert('top offset: ' + $('#bannercontent').offset().top + ' left offset: ' + $('#bannercontent').offset().left);
}
});</script>
<div class="clear:both;"></div>
<div id="container" class="container row">
<div role="main" class="<?php echo $cs_layout;?>" >
<?php
/* Run the loop to output the post.
* If you want to overload this in a child theme then include a file
* called loop-single.php and that will be used instead.
*/
//get_template_part( 'loop', 'single_cs_artist' );
?>
<?php if ( have_posts() ): while ( have_posts() ) : the_post(); ?>
<?php
//showing meta start
$cs_artist = get_post_meta($post->ID, "cs_artist", true);
if ( $cs_artist <> "" ) {
$xmlObject = new SimpleXMLElement($cs_artist);
$cs_layout = $xmlObject->cs_layout;
$cs_sidebar_left = $xmlObject->cs_sidebar_left;
$cs_sidebar_right = $xmlObject->cs_sidebar_right;
$artist_release_date = $xmlObject->artist_release_date;
$artist_social_share = $xmlObject->artist_social_share;
$artist_buy_amazon = $xmlObject->artist_buy_amazon;
$artist_buy_apple = $xmlObject->artist_buy_apple;
$artist_buy_groov = $xmlObject->artist_buy_groov;
$artist_buy_cloud = $xmlObject->artist_buy_cloud;
}
//showing meta end
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="heading"><?php the_title(); ?></h1>
<div class="in-sec">
<?php
// getting featured image start
$image_id = get_post_thumbnail_id ( $post->ID );
if ( $image_id <> "" ) {
//$image_url = wp_get_attachment_image_src($image_id, array(208,208),true);
$image_url = cs_attachment_image_src($image_id, 208, 208);
$image_url = $image_url;
//$image_url_full = wp_get_attachment_image_src($image_id, 'full',true);
$image_url_full = cs_attachment_image_src($image_id, 0, 0);
$image_url_full = $image_url_full;
}
else {
$image_url = get_template_directory_uri()."/images/admin/no_image.jpg";
$image_url_full = get_template_directory_uri()."/images/admin/no_image.jpg";
}
//$image_id = get_post_thumbnail_id ( $post->ID );
//$image_url = wp_get_attachment_image_src($image_id, array(208,198),true);
//$image_url_full = wp_get_attachment_image_src($image_id, 'full',true);
// getting featured image end
?>
<div class="light-box artist-tracks artist-detail <?php if($image_id == "") echo "no-img-found";?> ">
<div id="main-container">
<div id="leftcolumn">
<a rel="prettyPhoto" name="<?php the_title(); ?>" href="<?php echo $image_url_full?>" class="thumb" >
<?php echo "<img src='".$image_url."' />";?>
</a>
<br>
<br>
<div id="inpostgallery"><?php echo do_shortcode('[inpost_gallery thumb_width="104" thumb_height="104" post_id="' . get_the_ID() . '" thumb_margin_left="0" thumb_margin_bottom="0" thumb_border_radius="2" thumb_shadow="0 1px 4px rgba(0, 0, 0, 0.2)" js_play_delay="3000" id="" random="0" group="0" border="" type="yoxview" show_in_popup="0" artist_cover="" artist_cover_width="200" artist_cover_height="200" popup_width="800" popup_max_height="600" popup_title="Gallery"][/inpost_gallery]'); ?></div>
</div>
<div id="rightcolumn">
<div class="desc">
<p style="font-size:12px;"><span class="bold" style="text-transform:uppercase; color:#262626;"><?php _e('Categories', CSDOMAIN); ?> :</span>
<?php
/* translators: used between list items, there is a space after the comma */
$before_cat = " ".__( '',CSDOMAIN );
$categories_list = get_the_term_list ( get_the_id(), 'artist-category', $before_cat, ', ', '' );
if ( $categories_list ): printf( __( '%1$s', CSDOMAIN ),$categories_list ); endif; '</p>';
?>
</p>
<br>
<h5><?php print_custom_field('stars:formatted_list', array('<li><img src="http://www.entertaininc.co.uk/wp-content/uploads/2015/09/gold-star-graphic-e1441218522835.png">[+value+]</li>','<ul>[+content+]</ul>') );
?></h5><br />
<h2><strong>Price</strong> <?php print_custom_field('price'); ?></h2> <br />
<h2><strong>Location</strong> <?php echo do_shortcode('[gmw_post_info info="city, country" divider=","]'); ?></h2><br />
<h4><?php _e('Description', CSDOMAIN); ?></h4>
<div class='txt rich_editor_text'>
<?php
the_content();
?>
</div>
<div class="clear"></div>
<?php edit_post_link( __( 'Edit', CSDOMAIN ), '<span class="edit-link">', '</span>' ); ?>
</div></div>
</div>
<div class="clear"></div>
</div>
</div>
<div class="in-sec">
<div class="artist-opts">
<div class="share-artist">
<?php
$cs_social_share = get_option("cs_social_share");
if($cs_social_share != ''){
$xmlObject_artist = new SimpleXMLElement($cs_social_share);
if($artist_social_share == 'Yes'){
social_share();
}?>
<?php }?>
</div>
<?php if($artist_buy_amazon != '' or $artist_buy_apple != '' or $artist_buy_groov != '' or $artist_buy_cloud != ''){?>
<div class="availble">
<h4><?php if($cs_transwitch =='on'){ _e('Buy This',CSDOMAIN); }else{ echo __CS('buy_now', 'Buy This'); }?></h4>
<?php
if ( $artist_buy_amazon <> "" ) echo ' <a target="_blank" href="'.$artist_buy_amazon.'" class="amazon-ind"> <span>';if($cs_transwitch =='on'){ _e('Amazon',CSDOMAIN); }else{ echo __CS('amazon', 'Amazon'); } echo '</span></a> ';
if ( $artist_buy_apple <> "") echo ' <a target="_blank" href="'.$artist_buy_apple.'" class="apple-ind"> <span>'; if($cs_transwitch =='on'){ _e('Apple',CSDOMAIN); }else{ echo __CS('itunes', 'iTunes'); } echo '</span></a> ';
if ( $artist_buy_groov <> "") echo ' <a target="_blank" href="'.$artist_buy_groov.'" class="grooveshark-ind"> <span>'; if($cs_transwitch =='on'){ _e('GrooveShark',CSDOMAIN); }else{ echo __CS('grooveshark', 'GrooveShark'); } echo '</span></a> ';
if ( $artist_buy_cloud <> "") echo ' <a target="_blank" href="'.$artist_buy_cloud.'" class="soundcloud-ind"> <span>'; if($cs_transwitch =='on'){ _e('SoundCloud',CSDOMAIN); }else{ echo __CS('soundcloud', 'SoundCloud '); } echo '</span></a> ';
?>
</div>
<?php }?>
<div class="clear"></div>
</div>
</div>
<?php
foreach ( $xmlObject as $track ){
if ( $track->getName() == "track" ) {
?>
<div class="in-sec">
<?php
enqueue_alubmtrack_format_resources();
?>
<div class="artist-tracks light-box">
<?php
$counter = 0;
foreach ( $xmlObject as $track ){
$counter++;
if ( $track->getName() == "track" ) {
echo "<div class='track'>";
echo "<h5>";
echo $artist_track_title = $track->artist_track_title;
echo "</h5>";
echo "<ul>";
if ($track->artist_track_playable == "Yes") {
echo '
<li>
<div class="cp-container cp_container_'.$counter.'">
<ul class="cp-controls">
<li><a style="display: block;" href="#" class="cp-play" tabindex="1"> <span>'; if($cs_transwitch =='on'){ _e('Play',CSDOMAIN); }else{ echo __CS('play', 'Play'); } echo '</span></a></li>
<li> <span>'; if($cs_transwitch =='on'){ _e('Pause',CSDOMAIN); }else{ echo __CS('pause', 'Pause'); } echo '</span></li>
</ul>
</div>
<div style="width: 0px; height: 0px;" class="cp-jplayer jquery_jplayer_'.$counter.'">
<img style="width: 0px; height: 0px; display: none;" id="jp_poster_0">
<audio src="'.$track->artist_track_mp3_url.'" preload="metadata" ></audio>
</div>
<script>
jQuery(document).ready(function($){
var myCirclePlayer = new CirclePlayer(".jquery_jplayer_'.$counter.'",
{
mp3: "'.$track->artist_track_mp3_url.'"
}, {
cssSelectorAncestor: ".cp_container_'.$counter.'",
swfPath: "'.get_template_directory_uri().'/scripts/frontend/Jplayer.swf",
wmode: "window",
supplied: "mp3"
});
});
</script>
</li>
';
}
if ($track->artist_track_downloadable == "Yes"){ echo '<li> <span>'; if($cs_transwitch =='on'){ _e('Download',CSDOMAIN); }else{ echo __CS('download', 'Download'); } echo '</span></li>'; }
if ($track->artist_track_lyrics <> "") { echo '<li> <span>'; if($cs_transwitch =='on'){ _e('Lyrics',CSDOMAIN); }else{ echo __CS('lyrics', 'Lyrics'); } echo '</span></li>';}
if ($track->artist_track_buy_mp3 <> ""){ echo '<li> <span>'; if($cs_transwitch =='on'){ _e('Buy Song',CSDOMAIN); }else{ echo __CS('buy_now', 'Buy Song'); } echo '</span></li>';}
echo "</ul>";
echo '
<div id="lyrics'.$counter.'" style="display:none;">
'.str_replace("\n","</br>",$track->artist_track_lyrics).'
</div>
';
echo "</div>";
}
}
?>
<div class="clear"></div>
</div>
</div>
<?php
}
}
?>
<div class="clear"></div>
<?php if ( get_the_author_meta( 'description' ) ) :?>
<div class="in-sec" style="margin-top:20px;">
<div class="about-author">
<div class="avatars">
<?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'PixFill_author_bio_avatar_size', 53 ) ); ?>
</div>
<div class="desc">
<h5><?php _e('About', CSDOMAIN); ?> <?php echo get_the_author(); ?></h5>
<p class="txt">
<?php the_author_meta( 'description' ); ?>
</p>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div>
<?php endif; ?>
</div>
<?php endwhile; endif; // end of the loop. ?>
<?php comments_template( '', true ); ?>
</div>
<?php if( $cs_layout != "sixteen columns left" and isset($show_sidebar) ) { ?>
<!--Sidebar Start-->
<div class="one-third column left">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar($show_sidebar) ) : ?>
<?php endif; ?>
</div>
<!--Sidebar Ends-->
<?php }?>
<div class="clear"></div><!-- #content -->
</div><!-- #container -->
<div class="clear"></div>
<?php get_footer(); ?>
You need to use jQuery UI library (draggable) - https://jqueryui.com/draggable/
And then read the offset of the div or so
You also can use a jquery plugin named draggabilly. See the event dragMove or dragEnd. Hope it helps.
I am using the Rockit Now wordpress theme, which comes with a music player widget. When adding the widget to a sidebar, you have the followings options-
Title- (a section to type text..)
Artist for playlist- (a dropdown menu with all artist post names)
No of tracks to play- (a section to type a number..)
I am trying to display this widget in my artist page template so that it appears on each artist page with the music for that particular artist post.
I have added the following to my single-artists.php page template-
<?php the_widget( 'cs_music_player' ); ?>
This has successfully called the widget as I am now receiving the message 'No Results Found' on the page.. What I need to do is be able to select the options as above in the php.. I unfortunately can't work out how to do this..
Here is the cs_music_playlist_widget.php code-
<?php
class cs_music_player extends WP_Widget
{
function cs_music_player()
{
$widget_ops = array('classname' => 'cs_music_player', 'description' => 'Select artist to Play Your Playlist.' );
$this->WP_Widget('cs_music_player', 'ChimpS : MusicPlayList', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = $instance['title'];
$get_post_slug = isset( $instance['get_post_slug'] ) ? esc_attr( $instance['get_post_slug'] ) : '';
$numtrack = isset( $instance['numtrack'] ) ? esc_attr( $instance['numtrack'] ) : '';
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">
<span>Title: </span>
<input class="upcoming" id="<?php echo $this->get_field_id('title'); ?>" size="40" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
</label>
</p>
<br />
<p>
<label for="<?php echo $this->get_field_id('get_post_slug'); ?>">
<span>artist for Playlist:</span>
<br /><br />
<select name="<?php echo $this->get_field_name('get_post_slug'); ?>" style="width:225px;">
<?php
global $wpdb,$post;
$args = array( 'post_type' => 'artists', 'posts_per_page' => -1,'post_status'=> 'publish');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<option <?php if($get_post_slug == $post->post_name){echo 'selected';}?> value="<?php echo $post->post_name;?>">
<?php echo substr(get_the_title(), 0, 20); if ( strlen(get_the_title()) > 20 ) echo "...";?>
</option>
<?php endwhile; ?>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('noot'); ?>">
<span>No Of Tracks To Play: </span>
<input class="upcoming" id="<?php echo $this->get_field_id('numtrack'); ?>" size="2" name="<?php echo $this->get_field_name('numtrack'); ?>" type="text" value="<?php echo esc_attr($numtrack); ?>" />
</label>
</p>
<div class="clear"></div>
<?php
}
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['get_post_slug'] = $new_instance['get_post_slug'];
$instance['numtrack'] = $new_instance['numtrack'];
return $instance;
}
function widget($args, $instance)
{
global $cs_transwitch;
extract($args, EXTR_SKIP);
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
$get_post_slug = empty($instance['get_post_slug']) ? ' ' : apply_filters('widget_title', $instance['get_post_slug']);
echo $before_widget;
$args=array(
'name' => $get_post_slug,
'post_type' => 'artists',
'post_status' => 'publish',
'showposts' => 1,
);
$get_posts = get_posts($args);
if( $get_posts ) {
$get_post_id = $get_posts[0]->ID;
}else{
$get_post_id = '';
}
// WIDGET display CODE Start
if (!empty($title))
echo $before_title . $title . $after_title;
global $wpdb;
if($get_post_id <> ""){
$artist_buy_amazon_db ='';
$artist_buy_apple_db = '';
$artist_buy_groov_db ='';
$artist_buy_cloud_db = '';
$cs_artist = get_post_meta($get_post_id, "cs_artist", true);
if ( $cs_artist <> "" ) {
$xmlObject = new SimpleXMLElement($cs_artist);
$artist_release_date_db = $xmlObject->artist_release_date;
$artist_buy_amazon_db = $xmlObject->artist_buy_amazon;
$artist_buy_apple_db = $xmlObject->artist_buy_apple;
$artist_buy_groov_db = $xmlObject->artist_buy_groov;
$artist_buy_cloud_db = $xmlObject->artist_buy_cloud;
enqueue_alubmtrack_format_resources('widget');
?>
<script>
jQuery(document).ready(function($){
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_<?php echo $get_post_id;?>",
cssSelectorAncestor: "#jp_container_<?php echo $get_post_id;?>"
}, [
<?php
$my_counter = 0;
foreach ( $xmlObject as $track ){
if ( $track->getName() == "track" ) {
if ( $my_counter < $instance['numtrack'] ) {
$artist_track_title = $track->artist_track_title;
$artist_track_mp3_url = $track->artist_track_mp3_url;
echo '{';
echo 'title:"'.$artist_track_title.'",';
echo 'mp3:"'.$artist_track_mp3_url.'"';
echo '},';
}
$my_counter++;
}
}
?>
], {
swfPath: "<?php echo get_template_directory_uri()?>/scripts/frontend/Jplayer.swf",
supplied: "mp3",
wmode: "window"
});
});
</script>
<!-- Now Playing Start -->
<div class="nowplaying">
<?php $cs_by = __('By: %s', CSDOMAIN); ?>
<h5><?php if($get_post_id <> ''){echo get_the_title($get_post_id);}?></h5>
<p><?php printf($cs_by, get_the_author()); ?> - <?php if(isset($artist_release_date_db)){ if($cs_transwitch =='on'){ _e('Release Date',CSDOMAIN); }else{ echo __CS('release_date', 'Release Date'). ' : '.$artist_release_date_db; }}?></p>
<div id="jquery_jplayer_<?php echo $get_post_id;?>" class="jp-jplayer"></div>
<div id="jp_container_<?php echo $get_post_id;?>" class="jp-audio">
<div class="jp-type-playlist">
<div class="jp-gui jp-interface">
<ul class="jp-controls">
<li>previous</li>
<li>play</li>
<li>pause</li>
<li>next</li>
<li>stop</li>
<li>mute</li>
<li>unmute</li>
<li>max volume</li>
</ul>
<div class="jp-progress">
<div class="jp-seek-bar">
<div class="jp-play-bar"></div>
</div>
</div>
<div class="jp-volume-bar">
<div class="jp-volume-bar-value"></div>
</div>
<div class="jp-current-time"></div>
<div class="jp-duration"></div>
<ul class="jp-toggles">
<li>Shuffle</li>
<li>Shuffle off</li>
<li>Repeat All</li>
<li>Repeat off</li>
</ul>
</div>
<div class="jp-playlist">
<ul>
<li></li>
</ul>
</div>
</div>
</div>
</div>
<?php if($artist_buy_amazon_db <> '' or $artist_buy_apple_db <> '' or $artist_buy_groov_db <> '' or $artist_buy_cloud_db <> ''){?>
<!-- Buy Now Start -->
<div class="buynow">
<h5 class="white"><?php if($cs_transwitch =='on'){ _e('BUY NOW',CSDOMAIN); }else{ echo __CS('buy_now', 'BUY NOW'); } ?></h5>
<ul>
<?php if($xmlObject->artist_buy_cloud <> ""){?><li> </li><?php }?>
<?php if($xmlObject->artist_buy_amazon <> ""){?><li> </li><?php }?>
<?php if($xmlObject->artist_buy_apple <> ""){?><li> </li><?php }?>
<?php if($xmlObject->artist_buy_groov <> ""){?><li> </li><?php }?>
</ul>
<!-- Buy Now End -->
<div class="clear"></div>
</div>
<div class="clear"></div>
<?php } //Buy now Condition end?>
<?php }else{?>
<div class="list-thumb">
<ul>
<li>
<h2><?php _e("No results found.",CSDOMAIN); ?></h2>
</li>
</ul>
</div>
<?php
}
} // if artist is not Selected
else{
echo '<div class="box-small no-results-found"> <h5>';
_e("No results found.",CSDOMAIN);
echo ' </h5></div>';
}
echo $after_widget;
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("cs_music_player");') );?>
the_widget accept three arguments:
$widget : the widget name, in your case cs_music_player
$instance : the widget instance settings. It's an array where your widget options goes. You can do something like this: array('title' => 'Your widget title', 'get_post_slug' => 'slug_of_your_artist', 'numtrack' => 10)
$args : an array of options used to display your widget. You can send an empty array to use the defaults, or just ignore that parameter.
In the end, your widget call will look like that:
global $post;
the_widget(
'cs_music_player',
array(
'title' => 'Your widget title',
'get_post_slug' => $post->post_name,
'numtrack' => 10
)
);
I'm having this problem where a view is not being run through the layout on the server, but in a local instance it works just fine without any changes. There are actually two views that have this problem, 'index' view and 'update' and 'create' view. Both of these views are partially rendering another view, 'index' is partially rendering '_view' and 'update' and 'create' are partially rendering '_form'. In the controller I'm specifying what layout should be used to render the views and made sure that the layout is not being overwritten from the action that handles each view. The code in question is as follows:
index.php
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
_view.php
<div class="well">
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('naslov')); ?>:</b>
<?php echo CHtml::encode($data->naslov); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('category_id')); ?>:</b>
<?php
$cat = Category::model()->findByPk($data->category_id);
$parent = $cat->parent()->find();
$c = $parent->title." / ".$cat->title;
echo CHtml::encode($c); ?>
<br />
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('image_path')); ?>:</b>
<?php echo CHtml::encode($data->image_path); ?>
<br />
</div>
update.php and create.php
<?php $this->renderPartial('_form', array('model'=>$model)); ?>
_form.php
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'news-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
),
)); ?>
// form code
<?php $this->endWidget(); ?>
and in the controller that extends a base controller i define which layout is to be used
public $layout='//layouts/column2';
I've looked through the application.log file trying to find anything that might cause this but didn't find anything.
EDITED:
Here is the controller Create action:
public function actionCreate() {
$model = new News;
if (isset($_POST['News'])) {
$model->attributes = $_POST['News'];
$model->body = $_POST['News']['body'];
$model->author = Yii::app()->user->id;
$model->meta_description = $_POST['News']['meta_description'];
$path = $this->upload_path;
$image_temp = CUploadedFile::getInstance($model, 'image_path');
$new_image_ext = pathinfo($image_temp, PATHINFO_EXTENSION);
$new_image_subpath = uniqid(rand(), true) . '.' . $new_image_ext;
$new_image_subpath = substr($new_image_subpath, 0, 1) . '/' . substr($new_image_subpath, 1, 1) . '/' . $new_image_subpath;
$new_image_path = $path . $new_image_subpath;
$model->image_path = $new_image_subpath;
if (!file_exists(dirname($new_image_path))) {
mkdir(dirname($new_image_path), 0777, true);
}
}
if ($model->save()) {
$image_temp->saveAs($new_image_path, false);
$this->redirect(array('view', 'id' => $model->id));
}
$this->render('create', array(
'model' => $model,
));
}
And the Update action:
public function actionUpdate($id) {
$model = $this->loadModel($id);
$this->pageTitle = "Vesti - Izmena vesti: " . $model->naslov . "";
if (isset($_POST['News'])) {
$model->attributes = $_POST['News'];
$model->body = $_POST['News']['body'];
$model->modified_on = date("d-m-y H:m:s");
$model->meta_description = $_POST['News']['meta_description'];
$model->attributes = $_POST['News'];
if ($_FILES['News']['name']['image_path'] != "") {
$uploadedFile = CUploadedFile::getInstance($model, 'image_path');
$path = $this->upload_path;
$image_temp = CUploadedFile::getInstance($model, 'image_path');
$new_image_ext = pathinfo($image_temp, PATHINFO_EXTENSION);
$new_image_subpath = uniqid(rand(), true) . '.' . $new_image_ext;
$new_image_subpath = substr($new_image_subpath, 0, 1) . '/' . substr($new_image_subpath, 1, 1) . '/' . $new_image_subpath;
$new_image_path = $path . $new_image_subpath;
$model->image_path = $new_image_subpath;
if (!file_exists(dirname($new_image_path))) {
mkdir(dirname($new_image_path), 0777, true);
}
} else {
unset($model->image_path);
}
if ($model->save()) {
if ($_FILES['News']['name']['image_path'] != "") {
$image_temp->saveAs($new_image_path, false);
}
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('update', array(
'model' => $model,
));
}
And the _form view:
<script type="text/javascript">
function showSEOServices() {
$("#seo_options").slideToggle();
}
function slugPopulate(s, d, a) {
if(a==1) {
var d = $("#News_category_id").val();
} else {
var s = $("#News_naslov").val();
}
$.ajax({
type: "GET",
url: 'index.php?r=news/slug',
data: "s=" + s + "&d=" + d,
success: function(data) {
$("#News_url_slug").val(data);
}
});
}
</script>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'news-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
),
)); ?>
<p class="note">Polja sa <span class="required">*</span> su obavezna.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'naslov'); ?>
<?php echo $form->textField($model,'naslov',array('size'=>60,'maxlength'=>255, 'onChange' => "slugPopulate(this.value, '', 1);")); ?>
<?php echo $form->error($model,'naslov'); ?>
</div>
<div class="row">
Top sekcija:<br>
<?php echo $form->checkBox($model,'top_section'); ?>
</div>
<div class="row">
Normalna sekcija:<br>
<?php echo $form->checkBox($model,'normal_section'); ?>
</div>
<div class="row">
Donja sekcija:<br>
<?php echo $form->checkBox($model,'bottom_section'); ?>
</div>
<div class="row">
Boja članka u listingu:<br>
<?php if($model->isNewRecord!='1'){ ?>
<input type="color" name="News[news_color]" id="News_news_color" value="<?php echo $model->news_color; ?>">
<?php } else { ?>
<input type="color" name="News[news_color]" id="News_news_color" value="">
<?php } ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'body'); ?>
<?php $this->widget('ext.editMe.widgets.ExtEditMe', array(
'model'=>$model,
'attribute'=>'body',
)); ?>
<?php echo $form->error($model,'body'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'category_id'); ?>
<?php echo $form->dropDownList($model, 'category_id', $model->getCategoryOptions(),array('onChange' => "slugPopulate('', this.value, 2);")); ?>
<?php echo $form->error($model,'category_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'image_path'); ?>
<?php echo CHtml::activeFileField($model, 'image_path'); ?>
<?php echo $form->error($model,'image_path'); ?>
</div>
<!-- FOTOGRAFIJA -->
<?php if($model->isNewRecord!='1'){ ?>
<div class="row">
<?php echo CHtml::image('/resources/uploads/news/'.$model->image_path,"image",array("width"=>200, "class" => "img-thumbnail")); ?>
</div>
<?php } ?>
<!-- FOTOGRAFIJA END -->
<!-- SEO opcije -->
<button type="button" onClick="showSEOServices()" class="btn btn-labeled btn-default">
<span class="btn-label"><i class="fa fa-map-marker"></i> </span>Prikaži opcije za SEO
</button>
<div id="seo_options" class="alert alert-info" style="display:none;">
<div class="row">
<?php echo $form->labelEx($model,'url_slug'); ?>
<?php echo $form->textField($model,'url_slug',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'url_slug'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'meta_title'); ?>
<?php echo $form->textField($model,'meta_title',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'meta_title'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'meta_description'); ?>
<?php echo $form->textArea($model,'meta_description',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'meta_description'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'meta_keywords'); ?>
<?php echo $form->textField($model,'meta_keywords',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'meta_keywords'); ?>
</div>
</div>
<!-- SEO opcije kraj -->
<div class="row">
<?php echo $form->labelEx($model,'status'); ?>
<?php echo $form->dropDownList($model, 'status', $model->getStatusOptions()); ?>
<?php echo $form->error($model,'status'); ?>
</div>
<div class="row buttons">
<button class="btn btn-success ladda-button" data-style="expand-right"><span class="ladda-label">Sačuvaj</span></button>
<?php //echo CHtml::submitButton($model->isNewRecord ? 'Kreiraj' : 'Sačuvaj', array("class" => "btn btn-success ladda-button", "data-style" => "expand-right")); ?>
</div>
<?php $this->endWidget(); ?>