Using simplemodal with wordpress - wordpress

I am trying to use simplemodal to have modal popups with text in wordpress posts. I've played around with various plugins but they have specific uses (such as the contact form, or another one I saw that displays a single note you can customize).
I've tried following this tutorial: http://wordpressthemescollection.com/ajax-wordpress-post-popup-with-simplemodal-and-jquery-488.html but the instructions are not very clear for people without advanced jquery or wordpress knowledge and it simply isn't working for me. The author does not explain where you put the function, for instance.
For anyone who's gotten simplemodal working in wordpress, without developing a plugin, can you please assist? Thank you.

The tutorial is a good start on a solution, but does not quite provide all of the details. There are also some changes that I would make. Here is what I would do to get it working:
Create the Ajax Handler template and page
Make sure the link you want to use to open the modal includes the postpopup class and has the post ID in the rel attribute.
Create a js/ folder in your theme directory
Download SimpleModal 1.4.1 and place the file in the js/ folder
Create a custom JavaScript file (site.js) and place it in the js/ folder
Put the following code in site.js:
.
jQuery(function ($) {
$('a.postpopup').click(function(){
id = this.rel;
$.get('http://yourdomain.com/ajax-handler/?id='+id, function (resp) {
var data = $('<div id="ajax-popup"></div>').append(resp);
// remove modal options if not needed
data.modal({
overlayCss:{backgroundColor:'#000'},
containerCss:{backgroundColor:'#fff', border:'1px solid #ccc'}
});
});
return false;
});
});
Add the following code to your theme's functions.php file:
.
function my_print_scripts() {
if (!is_admin()) {
$url = get_bloginfo('template_url');
wp_enqueue_script('jquery-simplemodal', $url . '/js/jquery.simplemodal.1.4.1.min.js', array('jquery'), '1.4.1', true);
wp_enqueue_script('my_js', $url . '/js/site.js', null, '1.0', true);
}
}
add_action('wp_print_scripts', 'my_print_scripts');
That should get it working for you. Make sure you have the wp_footer() function in your theme's footer. I re-worked the way the modal window was being called so that the auto-centering of the content works.

Related

WordPress tinymce default link's target

I'm trying to edit the WordPress TinyMCE editor so all the links has the target = "_blank". I've tried with jquery to set the 'Open link in new tab' checkbox to be always checked but, no results.
Thank you
You can accomplish this with the default_link_target setting in your TinyMCE configuration: https://www.tinymce.com/docs/plugins/link/#default_link_target
Here is a TinyMCE Fiddle of this in action: http://fiddle.tinymce.com/31faab
To do this in Wordpress you will need to create a simple plugin that modifies this setting as TinyMCE is loaded. It would look something like this:
<?php
add_filter('tiny_mce_before_init', 'add_my_options', 1000);
function add_my_options($opt) {
$opt['default_link_target'] = "_blank";
return $opt; //you must return $opt to not break things
}
?>
If you have never created a WP plugin they are not hard to build and there are plenty of examples on the web.

How to add "code" format button to Tinymce 4 in WordPress 3.9

Tinymce offers an inline code formatting option that wraps the <code> tag around content. But WordPress does not include this. I think that there must be an easy way to enable it. I have seen discussing on how to do this in earlier versions of WP (with Tinymce 3) in threads like Add "code" button to wordpress tinyMCE ,
but I can't see how to "translate" this into Tinymce 4.
I tried the following. It gives me the Source Code but not the code tag.
// Add <code> support to the Visual Editor
// Load the code TinyMCE plugin
function my_TinyMCEplugins($plugin_array) {
$plugin_array['code'] = get_bloginfo('template_directory') . '/inc/code/plugin.min.js';
return $plugin_array;
}
add_filter('mce_external_plugins', 'my_TinyMCEplugins');
// Add the code button into the toolbar
function my_TinyMCE($in) {
$in['toolbar2'].=',code';
return $in;
}
add_filter('tiny_mce_before_init', 'my_TinyMCE' );
Thanks for any help!
Actually the TinyMCE code plugin is NOT used to insert <code> tags. It is used to edit the source html code, which is redundant in wordpress since you can just click the 'text' tab.
This wordpress plugin will add that functionality for you: https://wordpress.org/plugins/tinymce-code-button/screenshots/.

Loading javascript into wordpress wp_enqueue_script() problem

I am trying to get my custom javascript (jQuery) to load correctly in Wordpress.
I know you have to use wp_enqueue_script() to do this correctly. However the problem I have is that the result is not my script, but in the place I should have javascript I have the code for a 404 page !
I've tried two ways of enqueueing the script :
wp_enqueue_script('sitescript', get_bloginfo('template_directory').'/javascript/sitescript.js', array('jquery'),1);
just above wp_head()
and :function my_script_load() {
wp_enqueue_script('sitescript', get_bloginfo('template_directory').'/javascript/sitescript.js', array('jquery'),null);
}
add_action('init', 'my_script_load');
in functions.php
both methods have the same effect. When I inspect the HTML in firebug I find the script is corredtly referenced :
<script src="http://localhost/wordpress/wp-content/themes/doric2011/javascript/sitescript.js" type="text/javascript">
however when I inspect the script itself I find the following (an extract) :`
Page not found | Nick Kai Nielsen
and so on... It is a HTML output for a 404 page, but occupying a space where javascript should be...
Needless to say the script does not work.
I have only had this problem since updating to 3.1 and it does the same thing if I try loading highslide.js and highslide.config.js (professionally written scripts). The script I wish to load is already working on my site and I want to go on using it in the new theme I am developing.
has anyone any idea of what is happening ? And, of course, what should I do about it ?
This is a local installation - I'm not risking breaking my site until this is sorted out.
Try:
add_action('init', 'my_script_load');
function my_script_load() {
wp_register_script('sitescript', get_bloginfo('template_directory').'/javascript/sitescript.js', array('jquery'), true);
wp_enqueue_script('sitescript');
}
Assuming your javascript file is in the proper location (and the URL isn't pointing to a spot where the JS file isn't...) try this:
function add_my_scripts() {
$templatedir = get_bloginfo('template_directory');
if(!is_admin()) {
wp_register_script( 'sitescript', $templatedir . '/javascript/sitescript.js');
wp_enqueue_script( 'sitescript' );
}
}
add_action( 'init', 'add_my_scripts');

Drupal 6: Theme Developer gives too common candidate name, nothing specific

I'm working on a restaurant directory site. I have restaurant details page that I need to implement gmap, slideshow, etc. So I need a specific page.tpl and Theme Developer gives the info as below
alt text http://img.skitch.com/20100708-b9af98fb8mpckai5wfpmktxwgf.jpg
but site's about us, contact us, faq, etc pages has same candidate name as page-node.tpl.php . So I can't use that :/
Why isnt there anything like page-restaurant.tpl.php
how can I solve this? Appreciate helps so much! thanks a lot!
[SORTED]
<script type="text/javascript">
window.onload = function() {
load();
}
window.onunload = function() {
GUnload();
}
</script>'
If you are just wanting to add Javascript code, you can use the CSS class provided with most themes. For example, Zen will give you
<body class="not-front logged-in node-type-restaurant two-sidebars page-restaurant">...</body>
which you can detect with jQuery as
$(document).ready() { $('.page-restaurant').Myfunction(); }
Regarding slideshow, I've had good luck with Views Slideshow, which provides a block you can just place in a region on your page.
We had a similar question yesterday.
The logic of drupal is that the page should be for the common elements of a page accross all types of page and content types. Page is the top level template, if you are trying to change that per content type you may not have seperated your theme correctly. You have node theming for differentiating between the different types of node. The format is node-[NODE TYPE].tpl.php
Have you created a content type "restaurant"? If you do this, you may find modules like gmap will help you out.
Add the following function to your template.php file. Replace "themename" with the actual name of your theme. This assumes you've created a separate content type for "restaurant" - I gather you have from the previous answers and comments. You'll get an option to use page-restaurant.tpl.php once you upload the edited template.php file and refresh the theme registry.
function themename_preprocess(&$vars, $hook) {
switch ($hook){
case 'page':
// Add a content-type page template in second to last.
if ('node' == arg(0)) {
$node_template = array_pop($vars['template_files']);
$vars['template_files'][] = 'page-' . $vars['node']->type;
$vars['template_files'][] = $node_template;
}
break;
}
return $vars;
}

No feed output when working with Friendfeed and Wordpress API?

This is probably a Wordpress issue more than a Friendfeed issue but could be either. I have tried to debug with Firebug, wP_DEBUG, and error_log() but no issues have appeared.
I'm trying to initalize a set of ajax-powered feeds (using Friendfeed API) in the middle sidebar on various Wordpress category pages using a conditional statement. I can get one feed to display on one page no problem but when I add the conditional, it no longer displays.
Relevant lines:
function farmball_feed() {
global $post;
if ( is_category('3')) { $category = "farmball";
} elseif ( is_category('4')) { $category = "new-redsox";
} else { $category = "red-sox-on-farmball"; }
$feed = $friendfeed->fetch_room_feed($category, null, 0+($ind*30), 30);
Here is the full plugin code: http://www.pastie.org/private/vja7eisby93e3odh628xg
I call the function within the plugin using the following line in the sidebar-[category].php template file:
<?php if (function_exists('farmball_feed')) { farmball_feed(); } ?>
Here is the full sidebar code: http://pastie.org/private/lgxsdwxja08v93pkmvz3ug
I've checked in with the WP.org forum, MIRC, WP Tavern forum, and Friendfeed forum but no solution yet. I looked into the Developing a Widget codex but this plugin uses a couple other JS files so I don't think making it a custom widget would work. I'm not great with PHP so the answer could be a simple one. Appreciate the help.
Demo site: http://farmball.com/boston
It turned out to be an issue with where the JS plugin was being initialized. We had to add a line of php code to the friendfeed file which linked to the sidebar php code. Instead of using a conditional, we created unique sidebar template files, each calling js on its own. No conditional needed.

Resources