ShortCode Wordpress doesnt work - php

I have a shortcode that I put in my post but somehow it doent execute for some reasong. Here is the code I have:
short-code.php:
add_shortcode('teammate',function($atts){
$classes=$atts['country'];
$imgUrl=$atts['img'];
$name=$atts['name'];
$description=$atts['description'];
echo '
<div class="member "'.$classes.'>
<div class="member-img">
<img src="'.$imgUrl.'">
</div>
<div class="member-desc">
<h1>'.$name.'</h1>
<p>'.$description.'</p>
</div>
<div class="clear"> </div>
</div>
';
});
Here is how I include the file in functions.php:
$includes = array(
'includes/theme-options.php', // Options panel settings and custom settings
'includes/theme-functions.php', // Custom theme functions
'includes/theme-actions.php', // Theme actions & user defined hooks
'includes/theme-comments.php', // Custom comments/pingback loop
'includes/theme-js.php', // Load JavaScript via wp_enqueue_script
'includes/sidebar-init.php', // Initialize widgetized areas
'includes/theme-widgets.php', // Theme widgets
'includes/short-code.php', // Custom shortcode file for side menu
'includes/team.php' //team shortcode
);
and here is what i put in my page:
<div class="outer-members">
<div class="inner-members">
[teammate name="Darko Petkovski" img="http://myurl.com/myimage.jpg" description="test" country="mc"]
</div>
</div>

Seems that the code is working ok, but the only problem is that shortcode isn't executing outside wp.

Related

onclick Modal box in single product page

I want to create a onclick modal in single product page. I have put together the following:
FILES
js/modal-jquery.js and modal-box.html are uploaded in child theme's directory.
css is in child theme's css.
I enqueued the jquery in functions.php
// Enqueue MODAL Jquery JS
function my_enqueue_stuff() {
if(is_singular( 'product' ))
{
wp_enqueue_script( 'modal-jquery-js', get_stylesheet_directory_uri() . '/js/modal-jquery.js');
// wp_enqueue_script( 'modal-box', get_stylesheet_directory_uri() . 'modal-box.html');
}
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );
LINK in functions.php
// POPUP LINK
add_action( 'woocommerce_before_add_to_cart_form', 'popup-modal', 3 );
function popup-modal() {
// $file = file directory to modal-box.html
echo '<a class="js-open-modal" href="#" data-modal-id="popup"> Click me </a>';
}
modal-box.html
<div id="popup" class="modal-box">
<header>
×
<h3>Modal Title</h3>
</header>
<div class="modal-body">
<p>Modal Body</p>
</div>
<footer>
Close Button
</footer>
</div>
I'm not sure if this is the right approach.
I've been trying to add modal-box.html into function popup-modal().
I've also tried to enqueue modal-box.html but it gives an error message Uncaught SyntaxError: expected expression, got '<'
How can I load the html file as an external file into the single product page? If this is not the right way to do it, how can I add a modal box to the single product page?
Thanks
Instead of is_singular( 'product' ) use woocommerce's own is_product()
For the modal, what about including it in the footer, also only on product pages, like this?:
function your_modal_footer(){
if( !is_product() ){
return;
}
?>
<div id="popup" class="modal-box">
<header>
×
<h3>Modal Title</h3>
</header>
<div class="modal-body">
<p>Modal Body</p>
</div>
<footer>
Close Button
</footer>
</div>
<?php
}
add_action('wp_footer', 'your_modal_footer');
I would add a style="display:none;" to the popup div and then make it visible onclick of the popup's trigger.

Custom page template works fine on local host but doesn't show up online

I created a custom page template for a wordpress theme , as long as I had the theme installed locally page was displayed and showed within it the custom post type associated with it , but when I loaded online theme and I created the page by selecting the template to be used the page content doesn't show up.
It seems that by selecting the page template is not created the page with this template , but creates a page with the content of the index.
this is my page code with the loop that shows a custom_post_type
<?php
/*
*Template Name: Partecipanti
*Description : Pagina che raggiude tutte le associazioni partecipanti
*/
?>
<?php get_header(); ?>
<div id="partecipanti" class="content-container row">
<h2 class="titolo-pagina"><?php the_title(); ?></h2>
<?php
$wpquery = new WP_Query(array(
'post_type' => 'partecipanti',
'posts_per_page' => -1,
));
while ($wpquery->have_posts()): $wpquery->the_post();
?>
<div class="container-partecipante col-lg-3 col-md-3 col-sm-4 col-xs-12 visible-xs">
<?php the_post_thumbnail() ?>
<h2 class="nome"><?php the_title() ?></h2>
</div>
<div class="flip-container container-partecipante col-lg-3 col-md-3 col-sm-4 col-xs-12 hidden-xs" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front">
<?php the_post_thumbnail() ?>
</div>
<div class="back">
<h2 class="nome"><?php the_title() ?></h2>
<a class="glyphicon glyphicon-plus" href="<?php the_permalink(); ?>"></a>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
Maybe you just forgot set Page Template in page's edit? Or it was bugged - try delete template, save page (to auto-remove page template), upload template, set it again and save.
Also check if page template is at all used - for example place plain HTML test before <div id="partecipanti" class="content-container row"> and check if is displayed.
Have you the same WordPress version and plugins installed? Maybe you missed changed setting?
Try with simple page template, for example default full-width - are editor content is displayed?
Or maybe you have the same bug like me with latest WP version - when page is child (have parent page), it's bugged and page template doesn't work + page is outputed as post instead page.
Check file permisions in your theme folder

Override action in wordpress

In file '/wp-includes/comment-template.php', in function comment_form() exist action - 'do_action('comment_form_before')'. Below this action written code
<div id="respond" class="comment-respond">
<h3 id="reply-title" class="comment-reply-title"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3>
I want to replace all this code by my own code. How I can do it?

Display PHP custom field within WordPress shortcode

I'm using the echo do_shortcode function to include an events calendar within a WP template. I need to display a custom field within the shortcode area, but can't get it to work. Below is my code. I need the custom field "tickets" to show in the a href="#" section (replacing the #).
The post is a custom post type called "event".
<?php echo do_shortcode('[eo_events]
<div class="date">
<div class="month">%start{M}%</div>
<div class="day">%start{j}%</div>
</div>
<div class="venue">
<h2 style="margin-bottom:-40px!important; padding-bottom:0;">%event_venue%</h2>
<br/>%event_venue_address%<br/>%event_venue_country%, %event_venue_postcode%
</div>
<div class="city"><h2>%event_venue_city%</h2></div>
<div class="tickets">
<h2>Tickets</h2>
</div>
[/eo_events]');
?>
get the custom field first and save it in a variable. You can use the variable later in the string.
<?php
$url = get_post_meta($post_id, 'tickets', true);
echo do_shortcode('[eo_events]
<div class="date"><div class="month">%start{M}%</div> <div class="day">%start{j}%</div></div> <div class="venue"><h2 style="margin-bottom:-40px!important; padding-bottom:0;">%event_venue%</h2> < br/> %event_venue_address%<br/>%event_venue_country%, %event_venue_postcode%</div> <div class="city" ><h2 >%event_venue_city%</h2></div> <div class="tickets">
<h2>Tickets</h2>
</div>
[/eo_events]');
?>

Drupal 7 - Adding blocks to a page

This is my current set up.
I have created a new custom theme with the following regions.
regions[header] = Header
regions[content] = Content
regions[footer] = Footer
page.tpl.php
<div id="Header">
<div class="row">
<div class="span12" style="text-align:center;padding-top:20px;">
<div><img src="logo.png" width="150" height="150" alt="KT Logo"></div>
</div>
</div>
<div class="row"> </div>
</div><!-- /Header -->
<div id="Navigation">
<div class="row" style="text-align:center;">
<div class="span12" style="text-align:center;">
<?php print render($page['header']); ?>
<hr class="style-two">
</div>
</div>
</div><!-- /Navigation -->
<div id="Content">
<div class="row"> </div>
<div class="row">
<div class="span8 offset1">
<h1><?php print $title; ?></h1>
</div>
</div>
<div class="row"> </div>
<div class="row">
<div class="span10 offset1">
<?php print render($page['content']) ?>
</div>
</div>
<div class="row"> </div>
</div><!-- /Content -->
<footer>
<div class="row">
<div class="span12">
<img src="separator.png" alt="separator">
<?php print render($page['footer']); ?>
</div>
</div>
<div class="row"> </div>
</footer>
</div><!-- /container -->
This all works well and I have created several basic pages fine. The problem comes when I want to have a custom "content type" with 2 blocks on a page, one with main content on left, one with a sidebar on right. Now I'm not completely understanding how the regions work.
I am wanting something like the sidebar_second effect but I'm not sure how it would set in with my widths. Here is a screenshot of my regions. http://goo.gl/XFVnl
So I think I need to change the way my content region is displayed so that it can include the sidebar region?
Thanks for any help
Content-type specific templates are usually node.tpl.php files, and page templates are page.tpl.php files.
page.tpl.php file is already included when you are using a node.tpl.php
First, add ALL the regions to the .info file of them theme. This directly affects which regions are available in blocks administration page.
It's not necessary to have all the regions you defined (in .info file) to present in all page.tpl.php files.
As you have 3 regions in the page.tpl.php file, leave it and it will continue to work.
But to override the page.tpl.php for specific node types, you will have to set them in the theme's template.php file. You simple "ask" Drupal to use this page.tpl.php file is node type is a "page" (for example).
Add this to your template.php file. Drupal will not look in to page--node-book.tpl.php file for an alternative page.tpl.php file if the node type is (machine name) is "book".
<?php
function themename_preprocess_page(&$variables) {
if (!empty($variables['node'])) {
$variables['theme_hook_suggestions'][] = 'page__node_' . $variables['node']->type;
}
}
?>
Now you can copy the page.tpl.php file to page--node-[type].tpl.php and make your changes there. Whatever you put in this file will be used for page template for that node type.
(Note: 2 hyphens between "page" and "node", and one between "node" and "[type]")
Remember to clear caches if you can't see the changes.
I believe the first step is to declare a sidebar region in your .module file along with your other regions even if it will not be displayed on every page.
In your page template you can check (psuedo-code)
if (isset($page['sidebar'])) {
<div sidebar float left theme this how you want>
print render($page['sidebar']);
</div>
}
Now when you create a block you can specify a specific path for it to show up on or a specific content type for it to show up on. The code above will check if the page has a block in your sidebar and render it accordingly.
You will probablly be more likely to get answers if you post on drupal stack exchange.
https://drupal.stackexchange.com/

Categories