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.
Related
I'm developing my own code to display the comment list and comment form.
What I need is to replace 'reply' button (only when is shown), with a comment form, next to the commentary to make the reply.
All the code I have so far is the following. Can someone help me fix it? Thanks.
<?php
$postid = XXX;
$comment_send = 'Send';
$comment_reply = 'Leave a Message';
$comment_reply_to = 'Reply';
$comment_author = 'Name';
$comment_email = 'E-Mail';
$comment_body = 'Comment';
$comment_url = 'Website';
$comment_cookies_1 = ' By commenting you accept the';
$comment_cookies_2 = ' Privacy Policy';
$comment_before = 'Registration isn\'t required.';
$comment_cancel = 'Cancel Reply';
$comments_args = array(
'fields' => array(
'author' => '<p class="comment-form-author"><br /><input id="author" name="author" aria-required="true" placeholder="' . $comment_author .'"></input></p>',
'email' => '<p class="comment-form-email"><br /><input id="email" name="email" placeholder="' . $comment_email .'"></input></p>',
'url' => '<p class="comment-form-url"><br /><input id="url" name="url" placeholder="' . $comment_url .'"></input></p>',
'cookies' => '<input type="checkbox" required>' . $comment_cookies_1 . '' . $comment_cookies_2 . '',
),
'label_submit' => __( $comment_send ),
'title_reply' => __( $comment_reply),
'cancel_reply_link' => __( $comment_cancel ),
'comment_field' => '<p class="comment-form-comment"><br /><textarea id="comment" name="comment" aria-required="true" placeholder="' . $comment_body .'"></textarea></p>',
'comment_notes_before' => __( $comment_before),
'comment_notes_after' => ''
);
comment_form( $comments_args, $postid );
?>
<ol class="commentlist">
<?php wp_list_comments(array('callback' => 'custom_comments_format'), get_comments(array('post_id' => $post_id))); ?>
<?php function custom_comments_format($comment, $args, $depth){ ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author">
<?php echo get_avatar( $comment, 56 ); ?>
<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author()) ?>
</div>
<div class="comment-moderation">
<?php if ($comment->comment_approved == '0') : ?>
<p><?php _e('Your comment is awaiting moderation.') ?></p>
<?php endif; ?>
</div>
<div class="comment-meta commentmetadata">
<p ><?php printf(__('%1$s at %2$s'), get_comment_date('j F, Y'), get_comment_time()) ?><?php edit_comment_link(__('(Edit)'),' ','') ?></p>
</div>
<div class="user-comment">
<?php comment_text() ?>
</div>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<?php } ?>
</ol>
Ps: The relation between a form and a reply comment is the comment_parent input. I can stack a new form instead the reply button, but I dont know how to set the comment_parent id into the comment_form( $comments_args, $postid ); as I did before to customize the form itself.
<input type="hidden" name="comment_parent" id="comment_parent" value="XXX">
<div class="reply">
<?php //comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
<?php
if($depth < $args['max_depth']){
$comments_args = array(
'comment_field' => '<input type=\'hidden\' name=\'comment_parent\' id=\'comment_parent\' value=\''.get_comment_ID().'\' />'
);
comment_form( $comments_args, $postid );
}
?>
</div>
Following my own steps, ive sloved the problem now its DONE like this.
<div class="reply">
<?php //comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
<?php
if($depth < $args['max_depth']){
$postid = $comment->comment_post_ID;
$comments_args['submit_field'] = '<p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Send"> <input type="hidden" name="comment_post_ID" value="'.$postid.'" id="comment_post_ID"> <input type="hidden" name="comment_parent" id="comment_parent" value="'.get_comment_ID().'"> </p>';
comment_form( $comments_args, $postid );
}
?>
</div>
I have a function I wrote in my functions.php page for a gallery to display on certain pages. It displays on custom templates, but now I need it to display on index.php Here is the code from my functions.php file:
function min_get_page_gallery( $echo = true) {
global $post;
$show_gallery = get_post_meta($post->ID, 'min_gallery-show', true);
if ( empty($show_gallery) ) {
return;
}
$gallery = get_post_meta($post->ID, 'min_image_advanced', false);
ob_start();
?>
<div class="gallery" id="gallery-<?php echo $post->ID; ?>">
<button class="gallery-move-left"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i></button>
<div class="image_container clearfix">
<?php
$count = count($gallery);
$num = ceil($count / 3);
//$width_container = $num * 100;
//$width_row = 100 / $num;
//echo '<div class="gallery_inner" style="width:' . $width_container . '%;">';
echo '<div class="gallery_inner">';
for ( $i = 0; $i < $count; $i++) {
if ( $i % 3 == 0 ) {
//echo '<div class="row" style="width: ' . $width_row . '%;">';
echo '<div class="row'. (0 == $i ? ' active': ' inactive') .'">';
}
echo '<div class="col-sm-4 img_container' . (0 == $i ? ' active': ' inactive') . '">';
echo wp_get_attachment_image($gallery[$i], 'thumb-gallery');
echo '</div>';
if ( $i % 3 == 2 || ($i+1) == $count) {
echo '</div>';
}
}
echo '</div>';
?>
</div>
<button class="gallery-move-right"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i></button>
</div>
<?php
$return = ob_get_contents();
ob_end_clean();
if ( $echo ) {
echo $return;
} else {
return $return;
}
}
That code works like a charm. Here is where I call it as min_get_page_gallery(); in awards.php where it works flawlessly:
<?php
/* Template Name: Awards Page Template */
get_header(); ?>
<div class="container" id="block-no-sidebar">
<h1><?php the_title(); ?></h1>
<div id="award-list">
<?php echo min_get_awards(); ?>
</div>
<div class="row">
<?php min_get_page_gallery(); ?>
</div>
<?php min_get_page_tabs(); ?>
</div>
<?php get_footer(); ?>
Now finally, I try to add the same function call of min_get_page_gallery(); in my index.php file like this:
<?php
// Silence is golden.
if ( ! defined ( 'ABSPATH' ) ) {
exit;
}
?>
<?php get_header(); ?>
<style class="take-to-head">
#block-main-content-with-sidebar { background: #ffffff; }
</style>
<div class="container" id="block-main-content-with-sidebar">
<div class="row">
<div class="col-sm-8">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
l('block-' . get_post_type());
endwhile; else:
l('block-none' );
endif;
?>
</div>
<div class="col-sm-4">
<?php l('block-sidebar'); ?>
</div>
</div>
<div class="row">
<?php min_get_page_gallery(); ?>
</div>
</div>
Is there something I'm missing??
Try to describe in more detail, what is wrong with your index.php? Is some output when load input.php, or blank page?
Is correctly defined ABSPATH? If not, your script exit on the beginning.
For more specific awareness of flow through the script, try to write there some echo
E.g.
<div class="row">
<?php echo "Before calling min_get_page_gallery()" ?>
<?php min_get_page_gallery(); ?>
<?php echo "After calling min_get_page_gallery()" ?>
</div>
Then look, if you can see the messages from echo before and after calling the desired function.
Ok, so I had to do some tweaking to get the meta to show in functions.php I added these lines:
$pagemain = is_page();
and then:
if ( $pagemain == is_page( 35393 ) ) {
$meta[] = array(
'id' => 'imageupload',
'post_types' => array( 'page'),
'context' => 'normal',
'priority' => 'high',
'title' => __( 'Image Gallery', 'min' ),
'fields' => array(
array(
'name' => __( 'Show', 'min' ),
'id' => "{$prefix}_gallery-show",
'desc' => __( '', 'meta-box' ),
'type' => 'checkbox',
'clone' => false,
),
array(
'id' => "{$prefix}_image_advanced",
'name' => __( 'Image Advanced', 'min' ),
'type' => 'image_advanced',
// Delete image from Media Library when remove it from post meta?
// Note: it might affect other posts if you use same image for multiple posts
'force_delete' => false,
// Maximum image uploads
//'max_file_uploads' => 2,
),
),
);
}
I am having a trouble with my website's pop-up widget. The problem is the pop-up appears when you enter or refresh the website but I can not close it. I click on the "X" button but nothing happens. The code:
<?php
/*
Plugin Name: WP Welcome Message
Plugin URI: http://www.a1netsolutions.com/Products/WP-Welcome-Message
Description: <strong>WP Welcome Message</strong> is a wordpress plugin, which help your to make any announcement, special events, special offer, signup message or such kind of message, displayed upon your website's visitors when the page is load through a popup box.
Version: 3.0
Author: Ahsanul Kabir
Author URI: http://www.ahsanulkabir.com/
License: GPL2
License URI: license.txt
*/
$wpwm_conf = array(
'VERSION' => get_bloginfo('version'),
'VEWPATH' => plugins_url('lib/', __FILE__),
);
function wpwm_admin_styles()
{
global $wpwm_conf;
wp_enqueue_style('wpwm_admin_styles',($wpwm_conf["VEWPATH"].'css/admin.css'));
if( $wpwm_conf["VERSION"] > 3.7 )
{
wp_enqueue_style('wpwm_icon_styles',($wpwm_conf["VEWPATH"].'css/icon.css'));
}
}
add_action('admin_print_styles', 'wpwm_admin_styles');
function wpwm_scripts_styles()
{
global $wpwm_conf;
$wpwmBoxSetly = get_option('wpwm_boxsetly');
if(!$wpwmBoxSetly){$wpwmBoxSetly=="fadeOut";}
wp_enqueue_script('wpwm_site_scripts',($wpwm_conf["VEWPATH"].'js/site_'.$wpwmBoxSetly.'.js'),array('jquery'),'',true);
wp_enqueue_style('wpwm_site_style',($wpwm_conf["VEWPATH"].'css/site.css'));
}
add_action('wp_enqueue_scripts', 'wpwm_scripts_styles');
function wpwm_defaults()
{
$wpwm_default = plugin_dir_path( __FILE__ ).'lib/default.php';
if(is_file($wpwm_default))
{
require $wpwm_default;
foreach($default as $k => $v)
{
$vold = get_option($k);
if(!$vold)
{
update_option($k, $v);
}
}
if(!is_multisite())
{
unlink($wpwm_default);
}
}
}
function wpwm_activate()
{
$wpwm_postsid = get_option( 'wpwm_postsid' );
if(!$wpwm_postsid)
{
$inputContent = 'Welcome to '.get_bloginfo('name').', '. get_bloginfo('description');
$new_post_id = wpwm_printCreatePost($inputContent);
update_option( 'wpwm_postsid', $new_post_id );
}
wpwm_defaults();
}
function wpwm_redirect()
{
$wpwm_fv = get_option('wpwm_fv');
if($wpwm_fv != 'fv')
{
echo 'Please setup your <strong>WP Welcome Message 2.0</strong> plugin. <input type="submit" value="Setup" class="button" />';
}
}
add_action( 'admin_footer', 'wpwm_redirect' );
function wpwm_admin_menu()
{
global $wpwm_conf;
if( $wpwm_conf["VERSION"] < 3.8 )
{
add_menu_page('WP Welcome Message', 'Welcome Msg', 'manage_options', 'wpwm_admin_page', 'wpwm_admin_function', (plugins_url('lib/img/icon.png', __FILE__)));
}
else
{
add_menu_page('WP Welcome Message', 'Welcome Msg', 'manage_options', 'wpwm_admin_page', 'wpwm_admin_function');
}
}
add_action('admin_menu', 'wpwm_admin_menu');
function wpwm_select( $iget, $iset, $itxt )
{
if( $iget == $iset )
{
echo '<option value="'.$iset.'" selected="selected">'.$itxt.'</option>';
}
else
{
echo '<option value="'.$iset.'">'.$itxt.'</option>';
}
}
function wpwm_update($key, $value)
{
if(isset($value) && !empty($value))
{
update_option($key, $value);
}
}
function wpwm_admin_function()
{
$wpwm_fv = get_option('wpwm_fv');
if($wpwm_fv != 'fv')
{
update_option('wpwm_fv', 'fv');
}
wpwm_update('wpwm_loc', $_POST["wpwm_loc"]);
wpwm_update('wpwm_log', $_POST["wpwm_log"]);
wpwm_update('wpwm_boxsetly', $_POST["wpwm_boxsetly"]);
wpwm_update('wpwm_bgstyle', $_POST["wpwm_bgstyle"]);
wpwm_update('wpwmTemplate', $_POST["wpwmTemplate"]);
wpwm_update('wpwm_onlyFirstVisit', $_POST["wpwm_onlyFirstVisit"]);
wpwm_update('wpwm_ststs', $_POST["wpwm_ststs"]);
$wpwmPID = get_option('wpwm_postsid');
wpwm_updatePost($_POST["wpwmeditor"], $wpwmPID);
if( isset($_POST["wpwmeditor"]) || isset($_POST["wpwmTemplate"]) )
{
echo '<div id="message" class="updated wpwm_updated"><p>Your data has been successfully saved.</p></div>';
}
global $wpwm_conf;
echo '<div id="wpwm_container">
<div id="wpwm_main">
<img src="',$wpwm_conf["VEWPATH"],'/img/uvg.png" id="wpwm_uvg" />
<h1 id="wpwm_page_title">WP Welcome Message</h1>';
?>
<div class="wpwm_box">
<div class="wpwm_box_title">Your Welcome Message
<form method="post" action="" id="wpwm_off_on"><input type="hidden" name="wpwm_ststs" value="<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
echo 'off';
}
else
{
echo 'on';
}
?>" /><input type="image" src="<?php echo $wpwm_conf["VEWPATH"]; ?>/img/<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
echo 'one-check_yes';
}
else
{
echo 'one-check_no';
}
?>.png" /></form>
</div>
<div class="wpwm_box_con">
<form method="post" action="" id="wpwm_content_form">
<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'off')
{
echo '<div id="wpwm_content_disable"></div>';
}
$wpwmPID = get_option('wpwm_postsid');
$wpwmContent = get_post($wpwmPID);
$wpwmContent = $wpwmContent->post_content;
$wpwmContent = apply_filters('the_content', $wpwmContent);
$wpwmContent = str_replace(']]>', ']]>', $wpwmContent);
if( $wpwm_conf["VERSION"] < 3.3 )
{
echo '<textarea name="wpwmeditor" style="width:100%; height:300px;"></textarea>';
}
else
{
wp_editor( $wpwmContent, 'wpwmeditor', array('textarea_rows' => 20, 'textarea_name' => 'wpwmeditor') );
}
?>
<input type="submit" value="save changes" />
</form>
</div>
</div>
<div class="wpwm_box">
<div class="wpwm_box_title">Settings</div>
<div class="wpwm_box_con">
<form method="post" action="">
<div class="row">
<label>On Which Page/Pages to Display : </label>
<select name="wpwm_loc">
<?php
$wpwmLoc = get_option( 'wpwm_loc' );
wpwm_select( $wpwmLoc, 'home', 'Home Page Only' );
wpwm_select( $wpwmLoc, 'all', 'All Pages' );
?>
</select>
</div>
<div class="row">
<label>Logged-in / Not Logged-in user : </label>
<select name="wpwm_log">
<?php
$wpwm_log = get_option( 'wpwm_log' );
wpwm_select( $wpwm_log, 'log', 'Logged-in Users Only' );
wpwm_select( $wpwm_log, 'nlog', 'Not Logged-in Users Only' );
wpwm_select( $wpwm_log, 'all', 'For All' );
?>
</select>
</div>
<div class="row">
<label>Message Box Animation Style : </label>
<select name="wpwm_boxsetly">
<?php
$wpwmBoxSetly = get_option( 'wpwm_boxsetly' );
wpwm_select( $wpwmBoxSetly, 'fadeOut', 'Fade Out' );
wpwm_select( $wpwmBoxSetly, 'slideUp', 'Slide Up' );
?>
</select>
</div>
<div class="row">
<label>Template : </label>
<select name="wpwmTemplate">
<?php
$wpwmTemplate = get_option( 'wpwmTemplate' );
wpwm_select( $wpwmTemplate, 'black-color', 'Dark Color Only' );
wpwm_select( $wpwmTemplate, 'black-white-color', 'White Color Only' );
wpwm_select( $wpwmTemplate, 'white-color', 'Full White Color Only' );
wpwm_select( $wpwmTemplate, 'black-striped', 'Dark Stripes' );
wpwm_select( $wpwmTemplate, 'black-white-striped', 'White Stripes' );
wpwm_select( $wpwmTemplate, 'white-striped', 'Full White Stripes' );
wpwm_select( $wpwmTemplate, 'bootstrap', 'Bootstrap Style' );
?>
</select>
</div>
<div class="row">
<label>Only For Fist Time Visit : </label>
<select name="wpwm_onlyFirstVisit">
<?php
$wpwm_onlyFirstVisit = get_option( 'wpwm_onlyFirstVisit' );
wpwm_select( $wpwm_onlyFirstVisit, 'on', 'Enable' );
wpwm_select( $wpwm_onlyFirstVisit, 'off', 'Disable' );
?>
</select>
</div>
<input type="submit" value="save changes" />
</form>
</div>
</div>
<?php
echo '</div>
<div id="wpwm_side">
<div class="wpwm_box">';
echo '<img src="',$wpwm_conf["VEWPATH"],'/img/wp-advert-1.png" />';
echo '</div><div class="wpwm_box">';
echo '<img src="',$wpwm_conf["VEWPATH"],'/img/wp-advert-2.png" />';
echo '</div>
</div>
<div class="wpwm_clr"></div>
</div>';
}
function wpwm_content()
{
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
$wpwm_onlyFirstVisit = get_option( 'wpwm_onlyFirstVisit' );
if( $wpwm_onlyFirstVisit == "on" )
{
if( (!isset($_SESSION["wpwm_session"])) || ($_SESSION["wpwm_session"] != 'off') )
{
wpwm_popupFirst();
}
}
else
{
wpwm_popupFirst();
}
}
}
function wpwm_popupFirst()
{
$wpwm_loc = get_option( 'wpwm_log' );
if(get_option('wpwm_ststs') == 'on')
{
if( $wpwm_loc == 'log' )
{
if ( is_user_logged_in() )
{
wpwm_popupCheckPage();
}
}
elseif( $wpwm_loc == 'nlog' )
{
if ( !is_user_logged_in() )
{
wpwm_popupCheckPage();
}
}
else
{
wpwm_popupCheckPage();
}
}
}
function wpwm_popupTemp()
{
$wpwmPID = get_option( 'wpwm_postsid' );
$wpwmTemplate = get_option('wpwmTemplate');
$content_post = get_post($wpwmPID);
$wpwmContent = $content_post->post_content;
$wpwmContent = apply_filters('the_content', $wpwmContent);
$wpwmContent = str_replace(']]>', ']]>', $wpwmContent);
$session_id = session_id();
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
echo '<span>',get_option('wpwm_dev1'),get_option('wpwm_dev2'),get_option('wpwm_dev3'),'</span>';
}
function wpwm_popupCheckPage()
{
if( ( get_option( 'wpwm_loc' ) ) == 'home' )
{
if( is_front_page() )
{
wpwm_popupTemp();
}
}
else
{
wpwm_popupTemp();
}
}
function wpwm_sessionID()
{
if(!isset($_SESSION)){session_start();}
if(isset($_SESSION["wpwm_session"]))
{
$_SESSION["wpwm_session"] = 'off';
}
else
{
$_SESSION["wpwm_session"] = 'on';
}
}
add_action( 'wp_head', 'wpwm_sessionID' );
function wpwm_posts_init()
{
$args = array
(
'public' => false,
'publicly_queryable' => false,
'show_ui' => false,
'show_in_menu' => false,
'rewrite' => array( 'slug' => 'wpwmposts' ),
'capability_type' => 'post',
'has_archive' => false,
'supports' => array( 'title', 'editor', 'excerpt' )
);
register_post_type( 'wpwmposts', $args );
}
add_action( 'init', 'wpwm_posts_init' );
function wpwm_getCurrentUser()
{
if (function_exists('wp_get_current_user'))
{
return wp_get_current_user();
}
else if (function_exists('get_currentuserinfo'))
{
global $userdata;
get_currentuserinfo();
return $userdata;
}
else
{
$user_login = $_COOKIE["USER_COOKIE"];
$current_user = $wpdb->get_results("SELECT * FROM `".$wpdb->users."` WHERE `user_login` = '".$user_login."' ;");
return $current_user;
}
}
function wpwm_printCreatePost($inputContent)
{
$newPostAuthor = wpwm_getCurrentUser();
$newPostArg = array
(
'post_author' => $newPostAuthor->ID,
'post_content' => $inputContent,
'post_status' => 'publish',
'post_type' => 'wpwmposts'
);
$new_post_id = wp_insert_post($newPostArg);
return $new_post_id;
}
function wpwm_updatePost($inputContent, $id)
{
$newPostAuthor = wpwm_getCurrentUser();
$newPostArg = array
(
'ID' => $id,
'post_author' => $newPostAuthor->ID,
'post_content' => $inputContent,
'post_status' => 'publish',
'post_type' => 'wpwmposts'
);
$new_post_id = wp_insert_post($newPostArg);
return $new_post_id;
}
add_action('wp_footer', 'wpwm_content', 100);
register_activation_hook(__FILE__, 'wpwm_activate');
?>
Finally, I managed to find where the problem is.
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
And find out there is no close function going on here:
<span id="wpwm_popClose">×</span>
So changed it with this:
<span id="wpwm_popClose" onclick="document.getElementById('pwm_hideBody').style.display='none'">×</span>
but when I edit this PHP code, WordPress gives me this error:
Parse error: syntax error, unexpected 'pwm_hideBody' (T_STRING), expecting ',' or ';' in /var/www/vhosts/derinuzay.org/httpdocs/wp-content/plugins/wp-welcome-message/wp-welcome-message.php on line 337
Could you please help me out about this error?
Try to add this:
jQuery('#wpwm_popClose').click(function() {
jQuery('#wpwm_hideBody').css('display', 'none');
});
inside the:
jQuery(document).ready(function() {
jQuery("html, body").css({"overflow": "hidden"});
});
What happens if you replace
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
With:
?>
<div id="wpwm_hideBody" class="<?php echo $wpwmTemplate; ?>-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
<?php echo $wpwmContent; ?>
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#wpwm_popClose').click(function() {
jQuery('#wpwm_hideBody').css('display', 'none');
});
});
</script>
<?php
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
)
);
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]