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
)
);
Related
I'm looking to echo part of an array, what is the best method of echo'ing part of an array into a data field
I have an array that has the terms => subscription and need to pull that field into my input data-subscription="[echo subscription in here ]"
$quantites_required = false;
$previous_post = $post;
$count = 0;
$tax_query_args = [
'post_type' => 'product',
'tax_query' => [
[
'taxonomy' => 'product_type',
'field' => 'name',
'terms' => 'subscription',
],
],
];
$tax_query = get_posts($tax_query_args);
global $grouped_product;
foreach ($tax_query as $post) {
global $post;
$price = get_post_meta(get_the_ID(), '_price', true);
?>
<li id="product-<?php the_ID();?>" <?php post_class();?>>
<div class="prod-name">
<div class="radio">
<input type="checkbox" id="product-<?php the_ID();?>" value="1" name="quantity[<?php the_ID();?>]" class="wc-grouped-product-add-to-cart-checkbox js-group-item-sel" <?php echo ($count != 0 ? '' : ' checked="checked"'); ?> data-subscription="[echo terms subrciptions here]" />
<label for="product-<?php the_ID();?>">
<?php echo the_title(); ?>
</label>
</div>
</div>
<div class="prod-price" data-price="<?php echo number_format($price, 2); ?>">
<p>
<?php echo wc_price($price); ?>
</p>
</div>
<div class="prod_flag">
<?php get_product_flags(true); //Hide featured for grouped child items. ?>
</div>
<?php
$count = $count + 1;
}
$count = 0;
Replace this line
<input type="checkbox" id="product-<?php the_ID();?>" value="1" name="quantity[<?php the_ID();?>]" class="wc-grouped-product-add-to-cart-checkbox js-group-item-sel" <?php echo ($count != 0 ? '' : ' checked="checked"'); ?> data-subscription="[echo terms subrciptions here]" />
with
<input type="checkbox" id="product-<?php the_ID();?>" value="1" name="quantity[<?php the_ID();?>]" class="wc-grouped-product-add-to-cart-checkbox js-group-item-sel" <?php echo ($count != 0 ? '' : ' checked="checked"'); ?> data-subscription="<?php echo ($tax_query_args['tax_query'][0]['terms']); ?>" />
This is from an unsupported WordPress plugin that I'm trying to revive. I'm getting an error in the following code which states
Fatal Error class WP_Widget not found on Line 7
It works with PHP 5.3.3 but not on 5.6 or any version of PHP 7. Any suggestions would be appreciated.
<?php
/**
*
* Widget Class
*/
class Twitter_Like_Box_Widget extends WP_Widget
{
var $_options;
function __construct( ) {
global $tlb;
$this->wpb_prefix = $tlb->get_domain();
$widget_ops = array( 'classname' => 'tlb_widget', 'description' => ' Display your Twitter followers along with a follow me button' ); // Widget Settings
$control_ops = array( 'id_base' => 'tlb_widget' ); // Widget Control Settings
parent::__construct( 'tlb_widget', 'Twitter Like Box', $widget_ops, $control_ops );
$this->_options = $tlb->getOptions();
}
//Function to init the widget values and call the display widget function
function widget($args,$instance)
{
$title = apply_filters('widget_title', $instance['title']); // the widget title
$username = $instance['username']; // the widget title
$total_number = $instance['total_number']; // the number of followers to show
$show_followers = $instance['show_followers']; // show followers or users i follow
$link_followers = $instance['link_followers']; // link followers to profile
$width = $instance['width']; // link followers to profile
$widget = array ( 'username' => $username ,'total' => $total_number , 'show_followers' => $show_followers ,'link_followers'=> $link_followers, 'width' => $width, 'options' => $this->_options);
echo $args['before_widget'];
if ( $title )
echo $args['before_title'] . $title . $args['after_title'];
$this->display_widget($widget);
echo $args['after_widget'];
}
//function that display the widget form
function form($instance)
{
global $tlb;
$defaults = array( 'total_number' => 10, 'show_followers' => 'followers','link_followers'=> 'on','title' => 'My Followers', 'username' => 'chifliiiii');
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<?php if( $tlb->error != '' && defined('DOING_AJAX')):?>
<div class="error">
<p><?php echo sprintf(__('Check you OAuth settings, there is a problem with the connection.',$this->wpb_prefix),admin_url('options-general.php?page=twitter-like-box-reloaded'));?></p>
</div>
<?php endif;?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:',$this->wpb_prefix);?></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 $instance['title']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('username'); ?>"><?php _e('Username (without #):',$this->wpb_prefix);?></label>
<input class="widefat" id="<?php echo $this->get_field_id('username'); ?>" name="<?php echo $this->get_field_name('username'); ?>'" type="text" value="<?php echo $instance['username']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('show_thumbs'); ?>"><?php _e('Show Followers or people you follow?',$this->wpb_prefix);?></label>
</p>
<ul>
<li>
<input type="radio" class="radio" <?php checked( $instance['show_followers'], 'followers' ); ?> id="<?php echo $this->get_field_id('show_followers'); ?>" name="<?php echo $this->get_field_name('show_followers'); ?>" value="followers"/> <?php _e('Followers',$this->wpb_prefix);?>
</li>
<li>
<input type="radio" class="radio" <?php checked( $instance['show_followers'], 'nofollowers' ); ?> id="<?php echo $this->get_field_id('show_followers'); ?>" name="<?php echo $this->get_field_name('show_followers'); ?>" value="nofollowers" /> <?php _e('People I follow',$this->wpb_prefix);?>
</li>
</ul>
<p>
<label for="<?php echo $this->get_field_id('total_number'); ?>"><?php _e('How many you want to show?',$this->wpb_prefix); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('total_number'); ?>" name="<?php echo $this->get_field_name('total_number'); ?>" type="text" value="<?php echo $instance['total_number']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('link_followers'); ?>"><?php _e('Link followers to their profiles?',$this->wpb_prefix); ?></label>
<input type="checkbox" class="checkbox" <?php checked( $instance['link_followers'], 'on' ); ?> id="<?php echo $this->get_field_id('link_followers'); ?>" name="<?php echo $this->get_field_name('link_followers'); ?>" value="on" />
</p>
<p>
<label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Widget width:',$this->wpb_prefix); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width') ; ?>'" type="text" value="<?php echo isset($instance['width']) ? $instance['width'] : '100%'; ?>" />
</p>
<p>
<?php _e('More settings',$this->wpb_prefix);?>
</p>
<?php
}
//function that save the widget
function update($new_instance, $old_instance)
{
$instance['title'] = strip_tags($new_instance['title']);
$instance['username'] = strip_tags( $new_instance['username'] )== '' ? 'chifliiiii' : strip_tags( $new_instance['username'] );
$instance['total_number'] = strip_tags($new_instance['total_number']);
$instance['show_followers'] = $new_instance['show_followers'];
$instance['link_followers'] = $new_instance['link_followers'];
$instance['width'] = $new_instance['width'];
//Delete transient in case exist
$key = 'tlb_widgets_' . $instance['username'];
delete_transient($key);
return $instance;
}
//Finally thevfunction that create the widget
static function get_tlb_widget($widget)
{
global $tlb,$you;
$wpb_prefix = $tlb->get_domain();
$twitter = self::fetch_twitter_followers($widget);
ob_start();
if( !empty($you['error']) && '32' == $you['code']) {
echo $you['error'];
}
else
{
?>
<style type="text/css">
<?php echo $widget['options']['custom_css'];?>
</style>
<div id="tlb_container" style="width: <?php echo isset($widget['width']) ? $widget['width'] : 'auto';?>">
<?php if(isset($twitter['error']) ) :?>
<?php echo $twitter['error'];?>
<?php else : ?>
<div>
<div id="tlb_profile_img">
<a target="_blank" href="http://twitter.com/<?php echo $widget['username'];?>">
<img src="<?php echo $twitter['profile_image_url'];?>" width="44" height="44" align="left" alt="<?php echo $widget['username'];?>">
</a>
</div>
<div id="tlb_name">
<a target="_blank" href="http://twitter.com/<?php echo $widget['username'];?>">
<?php echo $widget['username'];?><span> <?php _e('on Twitter',$wpb_prefix);?></span>
</a>
</div>
<div id="tlb_follow">
<?php _e('Follow #',$wpb_prefix);?><?php echo $widget['username'];?>
</div>
</div><br>
<div style="padding:0; color:#637746;">
<div id="tlb_follow_total">
<?php
if ( $widget['show_followers'] == 'followers')
{
echo $twitter['followers_count'].' '.__('people follow',$wpb_prefix).' <strong>'. $widget['username'].'</strong>';
}
else
{
echo __('You follow ',$wpb_prefix). $twitter['friends_count'].__(' users',$wpb_prefix);
}
?>
</div>
<?php for($i=0; $i < $widget['total']; $i++) :?>
<span class="tlb_user_item">
<?php if($widget['link_followers'] == 'on' ): ?>
<a target="_blank" href="http://twitter.com/<?php echo $twitter['followers'][$i]['screen_name'];?>" title="<?php echo $twitter['followers'][$i]['screen_name'];?>" rel="nofollow">
<?php endif;?>
<img src="<?php echo $twitter['followers'][$i]['profile_image_url'];?>" width="48" height="48" alt="<?php echo $twitter['followers'][$i]['screen_name'];?>">
<span><?php echo substr($twitter['followers'][$i]['screen_name'], 0, 8);?></span>
<?php if($widget['link_followers'] == 'on' ): ?>
</a>
<?php endif;?>
</span>
<?php endfor;?>
<br style="clear:both">
</div>
<?php if ( $widget['options']['credits'] == 'true' ) echo '<div style="font-size:9px;text-align:right;">Widget By Timersys</div>';?>
<?php endif;//twitter error ?>
</div>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
</script>
<?php
}
$widget_code = ob_get_contents();
ob_end_clean();
return $widget_code;
}
/**
* Display widget
*/
static function display_widget($options){
echo Twitter_Like_Box_Widget::get_tlb_widget($options);
}
static function fetch_twitter_followers($options)
{
global $tlb,$you;
$cache_time = $tlb->_options['cache-time'];
$id = isset($options['id']) ? $options['id'] : 'widgets';
$key = 'tlb_'.$id.'_' . $options['username'];
// Let's see if we have a cached version
$followers = get_transient($key);
if ($followers !== false)
return $followers;
else
{
$tlb->connect();
$response = $tlb->connection->get("users/lookup", array('screen_name' => $options['username']));
if (Twitter_Like_Box_Widget::is_twitter_error($response))
{
// In case Twitter is down we return the last successful count
return get_option($key);
}
else
{
$json = $response;
#$you['name'] = $json[0]->name;
#$you['screen_name'] = $json[0]->screen_name;
#$you['followers_count'] = $json[0]->followers_count;
#$you['profile_image_url'] = $json[0]->profile_image_url;
#$you['friends_count'] = $json[0]->friends_count;
if ( $options['show_followers'] == 'followers' )
{
$fans = $tlb->connection->get('followers/ids',array('screen_name' => $options['username']));
}
else
{
$fans = $tlb->connection->get('friends/ids',array('screen_name' => $options['username']));
}
if (!Twitter_Like_Box_Widget::is_twitter_error($fans))
{
if ($options['total'] > 90 )
{
$fans_ids = array_chunk($fans->ids, 90);
$fans = array();
foreach ( $fans_ids as $ids_a )
{
$fans_ids = (string)implode( ',', $ids_a );
#$result = $tlb->connection->get('users/lookup',array('user_id' => $fans_ids ));
#$fans = array_merge($fans , $result );
}
}
else
{
$fans_ids = (string)implode( ',', array_slice($fans->ids, 0, $options['total']) );
#$fans = $tlb->connection->get('users/lookup',array('user_id' =>$fans_ids));
}
}
if( !Twitter_Like_Box_Widget::is_twitter_error($fans) && isset($fans[0]->screen_name) )
{
$followers = array();
for($i=0; $i < $options['total']; $i++)
{
$followers[$i]['screen_name'] = (string)$fans[$i]->screen_name;
$followers[$i]['profile_image_url'] = (string)$fans[$i]->profile_image_url;
}
$you['followers'] = $followers;
// Store the result in a transient, expires after 1 hour
// Also store it as the last successful using update_option
set_transient($key, $you, 60*60* $cache_time);
update_option($key, $you);
}
return $you;
}
}
}
static function is_twitter_error($response){
global $you,$tlb;
if(is_object($response) && isset($response->errors) )
{
$you['error'] = 'Error code: '. $response->errors[0]->code .'<br>Error message: '.$response->errors[0]->message;
$you['code'] = $response->errors[0]->code;
$tlb->log_error($you['error']);
return true;
}
if(is_object($response) && isset($response->ids) && empty($response->ids))
{
$you['error'] = '<br>Error message: You got no users to show. check if you have followers';
$tlb->log_error($you['error']);
return true;
}
return false;
}
} //end of class
Wordpress have ABSPATH variable defined in wp-config.php file, which contains the project's root path. Now we can include any file of wordpress codebase. eg.
require_once ABSPATH.'wp-includes/class-wp-widget.php';
I don't know the reason for the error, propably something with autoloading, but you can solve it if you include the file for the WP_Widget class in the first line.
require_once get_home_path()."wp-includes/class-wp-widget.php";
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.
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]
I am editing the code page of a wordpress post.
Now here is the full page code:
<?php
add_action( 'init', 'create_recipes' );
function create_recipes() {
//$portfolio_translation = get_option(THEME_NAME_S.'_cp_portfolio_slug','portfolio');
$labels = array(
'name' => _x('Recipes', 'Recipe General Name', 'crunchpress'),
'singular_name' => _x('Recipe Item', 'Recipe Singular Name', 'crunchpress'),
'add_new' => _x('Add New', 'Add New Event Name', 'crunchpress'),
'add_new_item' => __('Add New Recipe', 'crunchpress'),
'edit_item' => __('Edit Recipe', 'crunchpress'),
'new_item' => __('New Recipe', 'crunchpress'),
'view_item' => __('View Recipe', 'crunchpress'),
'search_items' => __('Search Recipe', 'crunchpress'),
'not_found' => __('Nothing found', 'crunchpress'),
'not_found_in_trash' => __('Nothing found in Trash', 'crunchpress'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => CP_PATH_URL . '/framework/images/recipe-icon.png',
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'supports' => array('title','editor','author','thumbnail','excerpt','comments'),
'rewrite' => array('slug' => 'recipes', 'with_front' => false)
);
register_post_type( 'recipes' , $args);
register_taxonomy(
"recipe-category", array("recipes"), array(
"hierarchical" => true,
"label" => "Recipe Categories",
"singular_label" => "Recipe Categories",
"rewrite" => true));
register_taxonomy_for_object_type('recipe-category', 'recipes');
register_taxonomy(
"recipe-tag", array("recipes"), array(
"hierarchical" => false,
"label" => "Recipe Tag",
"singular_label" => "Recipe Tag",
"rewrite" => true));
register_taxonomy_for_object_type('recipe-tag', 'recipes');
}
add_action('add_meta_boxes', 'add_recipes_option');
function add_recipes_option(){
add_meta_box('recipe-option', __('Recipes Options','crunchpress'), 'add_recipe_option_element',
'recipes', 'normal', 'high');
}
function add_recipe_option_element(){
$recipe_price = '';
$recipe_social = '';
$sidebars = '';
$right_sidebar_recipe = '';
$left_sidebar_recipe = '';
$recipe_detail_xml = '';
$select_chef = '';
$recipe_url = '';
foreach($_REQUEST as $keys=>$values){
$$keys = $values;
}
global $post;
$recipe_detail_xml = get_post_meta($post->ID, 'recipe_detail_xml', true);
$ingredients_settings = get_post_meta($post->ID, 'ingredients_settings', true);
$nutrition_settings = get_post_meta($post->ID, 'nutrition_settings', true);
if($recipe_detail_xml <> ''){
$cp_recipe_xml = new DOMDocument ();
$cp_recipe_xml->loadXML ( $recipe_detail_xml );
$recipe_price = find_xml_value($cp_recipe_xml->documentElement,'recipe_price');
$recipe_url = find_xml_value($cp_recipe_xml->documentElement,'recipe_url');
$recipe_social = find_xml_value($cp_recipe_xml->documentElement,'recipe_social');
$sidebars = find_xml_value($cp_recipe_xml->documentElement,'sidebars');
$left_sidebar_recipe = find_xml_value($cp_recipe_xml->documentElement,'left_sidebar_recipe');
$right_sidebar_recipe = find_xml_value($cp_recipe_xml->documentElement,'right_sidebar_recipe');
}
?>
<div class="event_options">
<ul class="recipe_class top-bg">
<li><h2>Recipe Options and Social Sharing</h2></li>
</ul>
<ul class="recipe_class">
<li class="panel-title">
<label for="recipe_social" > <?php _e('SOCIAL NETWORKING', 'crunchpress'); ?> </label>
</li>
<li class="panel-input">
<label for="recipe_social"><div class="checkbox-switch <?php
echo ($recipe_social=='enable' || ($recipe_social=='' && empty($default)))? 'checkbox-switch-on': 'checkbox-switch-off';
?>"></div></label>
<input type="checkbox" name="recipe_social" class="checkbox-switch" value="disable" checked>
<input type="checkbox" name="recipe_social" id="recipe_social" class="checkbox-switch" value="enable" <?php
echo ($recipe_social=='enable' || ($recipe_social=='' && empty($default)))? 'checked': '';
?>>
</li>
<li class="description"><p>Turn On/Off Social Sharing on Event Detail.</p></li>
</ul>
<div class="clear"></div>
<ul class="recipe_class">
<li class="panel-title">
<label for="recipe_price" > <?php _e('RECIPE PRICE', 'crunchpress'); ?> </label>
</li>
<li class="panel-input">
<input type="text" name="recipe_price" id="recipe_price" value="<?php if($recipe_price <> ''){echo $recipe_price;};?>" />
</li>
<li class="description"><p>Please enter your recipe price.</p></li>
</ul>
<div class="clear"></div>
<!--david-->
<ul class="recipe_class">
<li class="panel-title">
<label for="recipe_url" > <?php _e('RECIPE URL', 'crunchpress'); ?> </label>
</li>
<li class="panel-input">
<input type="text" name="recipe_url" id="recipe_url" value="<?php if($recipe_url <> ''){echo $recipe_url;};?>" />
</li>
<li class="description"><p>Please enter your url</p></li>
</ul>
<div class="clear"></div>
<!--david end-->
<?php echo show_sidebar($sidebars,'right_sidebar_recipe','left_sidebar_recipe',$right_sidebar_recipe,$left_sidebar_recipe);?>
<ul class="recipe_class">
<li class="panel-title">
<label><?php _e('Add Ingredients', 'crunchpress'); ?></label>
</li>
<li class="panel-input">
<input type="text" id="add-more-ingre" value="type title here" rel="type title here">
<div id="add-more-ingre" class="add-more-ingre"></div>
</li>
<li class="description"><p>Add Ingredients for this recipe.</p></li>
<div class="clear"></div>
<ul class="nut_table">
<li>
<div>SrNo</div>
<div>Name</div>
<div class="panel-delete-cc"> </div>
</li>
</ul>
<ul id="selected-ingre" class="selected-ingre nut_table_inner">
<li class="default-ingre-item" id="ingre-item">
<div class="ingre-item-counter"></div>
<div class="ingre-item-text"></div>
<div class="panel-delete-ingre"></div>
<input type="hidden" id="ingredients">
</li>
<?php
//Sidebar addition
if($ingredients_settings <> ''){
$ingre_xml = new DOMDocument();
$ingre_xml->loadXML($ingredients_settings);
$counter = 0;
foreach( $ingre_xml->documentElement->childNodes as $ingre_name ){
$counter++;
?>
<li class="ingre-item" id="ingre-item">
<div class="ingre-item-counter"><?php echo $counter;?></div>
<div class="ingre-item-text"><?php echo $ingre_name->nodeValue; ?></div>
<div class="panel-delete-ingre"></div>
<input type="hidden" name="ingredients[]" id="ingredients" value="<?php echo $ingre_name->nodeValue; ?>">
</li>
<?php }
}
?>
</ul>
</ul>
<div class="clear"></div>
<ul class="recipe_class">
<li class="panel-title">
<label> <?php _e('Add Nutrition', 'crunchpress'); ?> </label>
</li>
<li class="panel-input">
<input type="text" id="add-more-nutrition" value="type title here" rel="type title here">
<div id="add-more-nutrition" class="add-more-nutrition"></div>
</li>
<li class="description"><p>Add Nutrition for this recipe.</p></li>
<div class="clear"></div>
<ul class="nut_table">
<li>
<div>SrNo</div>
<div>Name</div>
<div class="panel-delete-cc"> </div>
</li>
</ul>
<br class="clear">
<ul id="selected-nutrition" class="selected-nutrition nut_table_inner">
<li class="default-nutrition-item" id="nutrition-item">
<div class="nut-item-counter"></div>
<div class="nutrition-item-text"></div>
<div class="panel-delete-nutrition"></div>
<input type="hidden" id="nutrition">
</li>
<?php
//Sidebar addition
if($nutrition_settings <> ''){
$ingre_xml = new DOMDocument();
$ingre_xml->loadXML($nutrition_settings);
$counter = 0;
foreach( $ingre_xml->documentElement->childNodes as $ingre_name ){
$counter++;
?>
<li class="nutrition-item" id="nutrition-item">
<div class="nut-item-counter"><?php echo $counter;?></div>
<div class="nutrition-item-text"><?php echo $ingre_name->nodeValue; ?></div>
<div class="panel-delete-nutrition"></div>
<input type="hidden" name="nutrition[]" id="nutrition" value="<?php echo $ingre_name->nodeValue; ?>">
</li>
<?php }
}
?>
</ul>
</ul>
<div class="clear"></div>
<ul class="recipe_class">
<li class="panel-title">
<label for="select_chef"><?php _e('SELECT CHEF', 'crunchpress'); ?></label>
</li>
<li class="panel-input">
<div class="combobox">
<select name="select_chef" id="select_chef">
<option>-- Select Chef --</option>
<?php
foreach(get_title_list_array('teams') as $our_team){?>
<option <?php if($select_chef == $our_team->post_name){echo 'selected';}?> value="<?php echo $our_team->post_name;?>"><?php echo $our_team->post_title?></option>
<?php }?>
</select>
</div>
</li>
<li class="description"><p>Please select Chef of this recipe.</p></li>
</ul>
<div class="clear"></div>
<input type="hidden" name="nutrition_type" value="nutrition">
<div class="clear"></div>
</div>
<div class="clear"></div>
<?php }
add_action('save_post','save_recipe_option_meta');
function save_recipe_option_meta($post_id){
$recipe_social = '';
$sidebars = '';
$right_sidebar_recpie = '';
$left_sidebar_recpie = '';
foreach($_REQUEST as $keys=>$values){
$$keys = $values;
}
if(defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE) return;
if(isset($nutrition_type) AND $nutrition_type == 'nutrition'){
$new_data = '<recipe_detail>';
$new_data = $new_data . create_xml_tag('recipe_price',$recipe_price);
$new_data = $new_data . create_xml_tag('recipe_url',$recipe_url);
$new_data = $new_data . create_xml_tag('recipe_social',$recipe_social);
$new_data = $new_data . create_xml_tag('sidebars',$sidebars);
$new_data = $new_data . create_xml_tag('right_sidebar_recipe',$right_sidebar_recipe);
$new_data = $new_data . create_xml_tag('left_sidebar_recipe',$left_sidebar_recipe);
$new_data = $new_data . '</recipe_detail>';
//Saving Sidebar and Social Sharing Settings as XML
$old_data = get_post_meta($post_id, 'recipe_detail_xml',true);
save_meta_data($post_id, $new_data, $old_data, 'recipe_detail_xml');
$recipe_setting_xml = '<recipe_ingredients>';
if(isset($_POST['ingredients'])){$ingredients = $_POST['ingredients'];
foreach($ingredients as $keys=>$values){
$recipe_setting_xml = $recipe_setting_xml . create_xml_tag('ingredients',$values);
}
}else{$ingredients = '';}
$recipe_setting_xml = $recipe_setting_xml . '</recipe_ingredients>';
//Saving Sidebar and Social Sharing Settings as XML
$old_data_ingre = get_post_meta($post_id, 'ingredients_settings',true);
save_meta_data($post_id, $recipe_setting_xml, $old_data_ingre, 'ingredients_settings');
$nutrition_setting_xml = '<recipe_nutrition>';
if(isset($_POST['nutrition'])){$nutrition = $_POST['nutrition'];
foreach($nutrition as $keys=>$values){
$nutrition_setting_xml = $nutrition_setting_xml . create_xml_tag('nutrition',$values);
}
}else{$nutrition = '';}
$nutrition_setting_xml = $nutrition_setting_xml . '</recipe_nutrition>';
//Saving Sidebar and Social Sharing Settings as XML
$old_data_nut = get_post_meta($post_id, 'nutrition_settings',true);
save_meta_data($post_id, $nutrition_setting_xml, $old_data_nut, 'nutrition_settings');
}
}
//FRONT END RECIPE LAYOUT
$recipe_div_size_num_class = array(
"Full-Image" => array("index"=>"1", "class"=>"sixteen ", "size"=>array(300,110), "size2"=>array(300,110), "size3"=>array(300,110)),
"Small-Thumbnail" => array("index"=>"2", "class"=>"sixteen", "size"=>array(445,175), "size2"=>array(445,175), "size3"=>array(445,175)));
// Print Recipe item
function print_recipe_item($item_xml){
wp_reset_query();
global $paged,$sidebar,$recipe_div_size_num_class,$post,$wp_query,$counter;?>
<!--<script src="<?php echo CP_PATH_URL;?>/frontend/js/jquery-filterable.js" type="text/javascript"></script>-->
<?php
if(empty($paged)){
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
}
//echo '<pre>';print_r($item_xml);die;
//print_r($event_div_size_num_class);
//$item_type = find_xml_value($item_xml, 'recipe-thumbnail-type');
$item_type = 'Full-Image';
// get the item class and size from array
$item_class = $recipe_div_size_num_class[$item_type]['class'];
$item_index = $recipe_div_size_num_class[$item_type]['index'];
$full_content = find_xml_value($item_xml, 'show-full-news-post');
if( $sidebar == "no-sidebar" ){
$item_size = $recipe_div_size_num_class[$item_type]['size'];
}else if ( $sidebar == "left-sidebar" || $sidebar == "right-sidebar" ){
$item_size = $recipe_div_size_num_class[$item_type]['size2'];
}else{
$item_size = $recipe_div_size_num_class[$item_type]['size3'];
}
// get the blog meta value
$header = find_xml_value($item_xml, 'header');
$num_fetch = find_xml_value($item_xml, 'num-fetch');
$num_excerpt = find_xml_value($item_xml, 'num-excerpt');
$category = find_xml_value($item_xml, 'category');
$show_filterable = find_xml_value($item_xml, 'show-filterable');
$category_name = '';
$category = ( $category == 'All' )? '': $category;
if( !empty($category) ){
$category_term = get_term_by( 'name', $category , 'recipe-category');
$category = $category_term->term_id;
$category_name = $category_term->name;
}
?>
<h2 class="heading"><?php echo $header;?></h2>
<?php
//Filterable Recipe Script start
if($show_filterable == 'Yes'){?>
<script>
jQuery(window).load(function() {
var filter_container = jQuery('#portfolio-item-holder<?php echo $counter?>');
filter_container.children().css('position','absolute');
filter_container.masonry({
singleMode: true,
itemSelector: '.portfolio-item:not(.hide)',
animate: true,
animationOptions:{ duration: 800, queue: false }
});
jQuery(window).resize(function(){
var temp_width = filter_container.children().filter(':first').width() + 20;
filter_container.masonry({
columnWidth: temp_width,
singleMode: true,
itemSelector: '.portfolio-item:not(.hide)',
animate: true,
animationOptions:{ duration: 800, queue: false }
});
});
jQuery('ul#portfolio-item-filter<?php echo $counter?> a').click(function(e){
jQuery(this).addClass("active");
jQuery(this).parents("li").siblings().children("a").removeClass("active");
e.preventDefault();
var select_filter = jQuery(this).attr('data-value');
if( select_filter == "All" || jQuery(this).parent().index() == 0 ){
filter_container.children().each(function(){
if( jQuery(this).hasClass('hide') ){
jQuery(this).removeClass('hide');
jQuery(this).fadeIn();
}
});
}else{
filter_container.children().not('.' + select_filter).each(function(){
if( !jQuery(this).hasClass('hide') ){
jQuery(this).addClass('hide');
jQuery(this).fadeOut();
}
});
filter_container.children('.' + select_filter).each(function(){
if( jQuery(this).hasClass('hide') ){
jQuery(this).removeClass('hide');
jQuery(this).fadeIn();
}
});
}
filter_container.masonry();
});
});
</script>
<ul id="portfolio-item-filter<?php echo $counter?>" class="category-list">
<li><a data-value="all" class="gdl-button active" href="#">All</a></li>
<?php
$categories = get_categories( array('child_of' => $category, 'taxonomy' => 'recipe-category', 'hide_empty' => 0) );
//$categories = get_the_terms( $post->ID, 'recipe-category' );
if($categories <> ""){
foreach($categories as $values){?>
<li><a data-value="<?php echo $values->term_id;?>" class="gdl-button" href="#"><?php echo $values->name;?></a></li>
<?php
}
}?>
<div class="clear"></div>
</ul>
<?php }else{?>
<h2 class="heading"><?php echo $category_name; ?></h2>
<?php }?>
<ul class="lightbox gallery_filterable" id="portfolio-item-holder<?php echo $counter?>">
<?php
$category = find_xml_value($item_xml, 'category');
$category = ( $category == 'All' )? '': $category;
if( !empty($category) ){
$category_term = get_term_by( 'name', $category , 'recipe-category');
$category = $category_term->slug;
}
if($show_filterable == 'Yes'){
query_posts(array(
'posts_per_page' => -1,
'post_type' => 'recipes',
'recipe-category' => $category,
'post_status' => 'publish',
'order' => 'ASC',
));
}else{
query_posts(array(
'posts_per_page' => $num_fetch,
'paged' => $paged,
'post_type' => 'recipes',
'recipe-category' => $category,
'post_status' => 'publish',
'order' => 'ASC',
));
}
while( have_posts() ){
global $post;
the_post(); ?>
<li class="all portfolio-item item alpha
<?php
$categories = get_the_terms( $post->ID, 'recipe-category' );
if($categories <> ''){
foreach ( $categories as $category ) {
echo $category->term_id." ";
}
}
?>">
<h3 class="heading">
<a href="<?php echo get_permalink();?>">
<?php
echo substr($post->post_title, 0, 20);
if ( strlen($post->post_title) > 20 ) echo "...";
?>
</a>
</h3>
<a href="<?php echo get_permalink();?>" class="caption">
<?php echo get_the_post_thumbnail($post->ID, $item_size);?>
<span class="hover-effect big zoom"></span>
</a>
<!--david-->
<article class="menu-det">
<p><?php echo strip_tags(mb_substr(get_the_content(),0,$num_excerpt));?> <a class="c-link" href="<?php echo $recipe_url;?>"><?php _e('Read More...', 'crunchpress'); ?></a></p>
</article>
</li>
<?php }//End While?>
</ul>
<div class="clear"></div>
<?php
if( find_xml_value($item_xml, "pagination") == "Yes" AND $show_filterable == 'No'){
pagination();
}
}
?>
Now, at the bottom of this page above, you will see a readmore link with the following content:
<article class="menu-det">
<p><?php echo strip_tags(mb_substr(get_the_content(),0,$num_excerpt));?> <a class="c-link" href="<?php echo $recipe_url;?>"><?php _e('Read M...', 'crunchpress'); ?></a></p>
</article>
Now the part giving me issues, is this one:
<?php echo $recipe_url;?>
So I basically only registered a new variable: $recipe_url;, and I replaced the original link href value of:
href="<?php echo get_permalink()?>"
with my new variable:
href="<?php echo $recipe_url;?>"
Now the url is empty on the webpage, even though a value is set. I even used some of the original variables included in the theme:
href="<?php echo $recipe_price;?>"
but it also does not populate a any url or href value..
Why is this? Am I calling it wrong?
Thanks
I don't have enough rep to add a comment to the question, but you don't appear to have added a closing brace to the add_recipe_option_element() method either.