Isotope with Fancybox filtering - fancybox

I implemented Isotope.js into my WordPress site. I use it to display gallery with Easy Fancybox plugin to add zooming functionality for images. Problem is with Isotope filtering. I added rel attribute to my images but when I filter categories Fancybox still cycles through all images.
I need to add rel attribute dynamically based on category I'm filtering. I'm struggling with this problem for 3 days now. I've read bunch of post, tried view things but still can't make it work.
Most of posts give solution with data-fancybox-group attribute but I can't use it I must use rel attribute (it doesn't work for me anyway).
Here's my WP code:
<ul id="filters">
<li>All</li>
<?php
$terms = get_terms("polygraphy-categories");
$count = count($terms);
if ( $count > 0 ){
foreach ( $terms as $term ) {
echo "<li><a class='filterbutton' href='#' data-filter='.".$term->slug."'>" . $term->name . "</a></li>\n";
}
}
?>
</ul>
<?php $the_query = new WP_Query( 'post_type=polygraphy' ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<div id="isotope-list">
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
$termsArray = get_the_terms( $post->ID, "polygraphy-categories" );
$termsString = "";
foreach ( $termsArray as $term ) {
$termsString .= $term->slug.' ';
}
?>
<div class="<?php echo $termsString; ?> poli">
<?php
if ( has_post_thumbnail()) {
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
echo '<a class="fancybox" href="' . $full_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
the_post_thumbnail('thumbnail');
echo '</a>';
}
?>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
And JS code:
jQuery(function ($) {
$(window).load(function(){
var $container = $('#isotope-list');
$container.isotope({
itemSelector : '.poli',
layoutMode : 'masonry'
});
var $optionSets = $('#filters'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('#filters');
$optionSets.find('.selected').removeClass('selected');
$this.addClass('selected');
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector });
return false;
});
});
});
I was told that this code should work but it doesn't:
$('.filterbutton').on("click", function(){
var selector = $(this).attr('data-filter');
if(selector == "*"){
$(".fancybox").attr("rel", "gallery");
} else{
$(selector).find(".fancybox").attr("rel", selector);
}
return false;
});

Related

Trying to hide utms if the values are empty

I run traffic for multiple clients on various platforms. The traffic goes to publisher sites that contain articles that link to client stores. I am trying to pass those utms through but don't want to duplicate or show unused utms
Here is the code that echos:
</script>
<?php endif; ?>
<?php $utm_source = isset($_GET['utm_source']) ? $_GET['utm_source'] : ""; ?>
<?php $utm_medium = isset($_GET['utm_medium']) ? $_GET['utm_medium'] : ""; ?>
<?php $utm_campaign = isset($_GET['utm_campaign']) ? $_GET['utm_campaign'] : ""; ?>
<?php $utm_term = isset($_GET['utm_term']) ? $_GET['utm_term'] : ""; ?>
<?php $utm_content = isset($_GET['utm_content']) ? $_GET['utm_content'] : ""; ?>
<?php $nbt = isset($_GET['nbt']) ? $_GET['nbt'] : ""; ?>
<?php $nb_placement = isset($_GET['nb_placement']) ? $_GET['nb_placement'] : ""; ?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$(function() {
$("a").attr('href', function(i, h) {
return h + (h.indexOf('?') != -1 ? "&utm_source=<?php echo $utm_source; ?
>&utm_medium=<?php echo $utm_medium; ?>&utm_campaign=<?php echo $utm_campaign; ?
>&utm_term=<?php echo $utm_term; ?>&utm_content=<?php echo $utm_content; ?>&nbt=<?PHP
echo $nbt; ?>&nb_placement=<?php echo $nb_placement; ?>" : "?utm_source=<?php echo
$utm_source; ?>&utm_medium=<?php echo $utm_medium; ?>&utm_campaign=<?php echo
$utm_campaign; ?>&utm_term=<?php echo $utm_term; ?>&utm_content=<?php echo
$utm_content; ?>&nbt=<?php echo $nbt; ?>&nb_placement=<?php echo $nb_placement; ?>");
});
});
});
</script>
Im trying to use something like this but I cant make it work
if (!empty($utm_source)) {
} else { echo "Niente";}
I am very new to coding so I apologize if this is a bad question

codeigniter form_validation with ajax

When i submit it with no data, it shows like this. but i want it to show on my modal, because i'm using the form_validation library.
enter image description here
This is my Controller:
$this->form_validation->set_rules('category_name','Category name','trim|required');
if($this->form_validation->run() == FALSE){
echo validation_errors();
} else{
$category = array(
"category_name" => $this->input->post('category_name')
);
$this->category_m->insert($category);
echo "Successfully Added.";
}
This is my ajax file:
$(document).on('submit', '#form' ,function(event){
event.preventDefault();
var form = $(this).serialize();
$.ajax({
url:"<?php echo base_url(); ?>category/operation",
type:"POST",
data:form,
success:function(data){
$('#form')[0].reset();
$('#mymodal').modal('hide');
$('#alert').fadeIn().html('<div class="alert alert-info">'+data+'</div>').fadeOut(5000);
table.ajax.reload();
}
})
});
This is not related to Codeigniter. It's JS/jQuery/HTML/...
Assuming that you have something like this in your HTML
<div id="mymodal">...</div>
Create another div#alert inside
<div id="alert">...</div>
And change the Javascript to something like
//You don't neet fadeIn/fadeOut
$('#alert').html('<div class="alert alert-info">'+data+'</div>');
$('#mymodal').modal('show');

Moodle block visibility per role on quiz attempt page

I have been following this tutorial successfully and created a small custom block.
I need this block to display on maths quiz/attempt.php pages but I have two problems.
The block displays for the admin user but does not display for students
How do I display the block only on selected quizes i:e maths and not english quizes
CODE:
class block_customfeedback extends block_base {
public function init() {
$this->title = get_string('customfeedback', 'block_customfeedback');
}
public function get_content() {
if ($this->content !== null) {
return $this->content;
}
$form .= "<form action='http://www.remoteserver.com/response.php' method='post'>";
$form .= "<label>Question ID</label> <input name='QuestionID' id='questionid' type='text' />";
$form .= "<label>Quiz Name</label> <input name='QuizName' id='quizname' type='text' />";
$form .= "<label>Your Feedback</label> <textarea name='Feedback' id='feedback' type='text' ></textarea>";
$form .= "<input type='submit' value='Submit' />";
$form .= "</form>";
$this->content = new stdClass;
$this->content->text = $form;
// $this->content->footer = 'Footer here...';
return $this->content;
}
public function applicable_formats() {
return array(
'all' => true
);
}
} // close class
You can make your block visible on quiz attempt page.
Steps:
Go to your quiz settings page.
Click on appearance
Click on show more
Change the value of "Show blocks during quiz attempts" to Yes.
Now login with student and check.

cakephp multiple forms with same action

I've got on my page several News, to every News we can add comment via form.
So actually I've got 3 News on my index.ctp, and under every News is a Form to comment this particular News. Problem is, when i add comment, data is taken from the last Form on the page.
I don;t really know how to diverse them.
i've red multirecord forms and Multiple Forms per page ( last one is connected to different actions), and i don't figure it out how to manage it.
Second problem is, i can't send $id variable through the form to controller ( $id has true value, i displayed it on index.ctp just to see )
This is my Form
<?php $id = $info['Info']['id']; echo $this->Form->create('Com', array('action'=>'add',$id)); ?>
<?php echo $this->Form->input(__('Com.mail',true),array('class'=>'form-control','field'=>'mail')); ?>
<?php echo $this->Form->input(__('Com.body',true),array('class'=>'form-control')); ?>
<?php echo $this->Form->submit(__('Dodaj komentarz',true),array('class'=>'btn btn-info')); ?>
<?php $this->Form->end(); ?>
and there is my controller ComsController.php
class ComsController extends AppController
{
public $helpers = array('Html','Form','Session');
public $components = array('Session');
public function index()
{
$this->set('com', $this->Com->find('all'));
}
public function add($idd = NULL)
{
if($this->request->is('post'))
{
$this->Com->create();
$this->request->data['Com']['ip'] = $this->request->clientIp();
$this->request->data['Com']['info_id'] = $idd;
if($this->Com->save($this->request->data))
{
$this->Session->setFlash(__('Comment added with success',true),array('class'=>'alert alert-info'));
return $this->redirect(array('controller'=>'Infos','action'=>'index'));
}
$this->Session->setFlash(__('Unable to addd comment',true),array('class'=>'alert alert-info'));
return false;
}
return true;
}
}
you are not closing your forms
<?php echo $this->Form->end(); ?>
instead of
<?php $this->Form->end(); ?>
for the id problem you should write
echo $this->Form->create(
'Com',
array('action'=>'add/'.$id
)
);
or
echo $this->Form->create(
'Com',
array(
'url' => array('action'=>'add', $id)
)
);

zend-form select optgroup, how to specify id

Hello i am using Zend Framework Form and have tried to get this example to work http://framework.zend.com/issues/browse/ZF-8252, but it fails xD
this is my code
$options = Array
(
[] => Qualsiasi Agente
[agenti_attivi] => Array
(
[4] => Giovanni Abc
[10] => Luigi Abc
[13] => Michela Abc
)
);
$agenti->addMultiOptions($options);
and the generated code is :
<select name="agente_id" id="agente_id" tabindex="6">
<option value="" label="Qualsiasi Agente" selected="selected">Qualsiasi Agente</option>
<optgroup id="agente_id-optgroup-Agenti attivi: " label="Agenti attivi: ">
<option value="4" label="Giovanni Abc">Giovanni Abc</option>
<option value="10" label="Luigi Capoarea">Luigi Abc</option>
<option value="13" label="Michela Abc">Michela Abc</option>
</optgroup>
</select>
where id="agente_id-optgroup-Agenti attivi: " is not xhtml valid Line 724, Column 44: value of attribute "id" must be a single token
i am using zend 1.11.10
thanks
Create a custom view helper FormSelect that extends the core FormSelect and then modify the code.
Include the path to your view helpers in the bootstrap file
protected function _initHelpers()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->addHelperPath('My/View/Helper', 'My_View_Helper');
}
The custom view helper. It's a copy of Zend_View_Helper_FormSelect but with small modification.
class My_View_Helper_FormSelect extends Zend_View_Helper_FormSelect
{
public function formSelect($name, $value = null, $attribs = null,
$options = null, $listsep = "<br />\n")
{
$info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
extract($info); // name, id, value, attribs, options, listsep, disable
// force $value to array so we can compare multiple values to multiple
// options; also ensure it's a string for comparison purposes.
$value = array_map('strval', (array) $value);
// check if element may have multiple values
$multiple = '';
if (substr($name, -2) == '[]') {
// multiple implied by the name
$multiple = ' multiple="multiple"';
}
if (isset($attribs['multiple'])) {
// Attribute set
if ($attribs['multiple']) {
// True attribute; set multiple attribute
$multiple = ' multiple="multiple"';
// Make sure name indicates multiple values are allowed
if (!empty($multiple) && (substr($name, -2) != '[]')) {
$name .= '[]';
}
} else {
// False attribute; ensure attribute not set
$multiple = '';
}
unset($attribs['multiple']);
}
// now start building the XHTML.
$disabled = '';
if (true === $disable) {
$disabled = ' disabled="disabled"';
}
// Build the surrounding select element first.
$xhtml = '<select'
. ' name="' . $this->view->escape($name) . '"'
. ' id="' . $this->view->escape($id) . '"'
. $multiple
. $disabled
. $this->_htmlAttribs($attribs)
. ">\n ";
// build the list of options
$list = array();
$translator = $this->getTranslator();
foreach ((array) $options as $opt_value => $opt_label) {
if (is_array($opt_label)) {
$opt_disable = '';
if (is_array($disable) && in_array($opt_value, $disable)) {
$opt_disable = ' disabled="disabled"';
}
if (null !== $translator) {
$opt_value = $translator->translate($opt_value);
}
$opt_id = ' id="' . $this->formatElementId($id . '-optgroup-' . $opt_value) . '"';
$list[] = '<optgroup'
. $opt_disable
. $opt_id
. ' label="' . $this->view->escape($opt_value) .'">';
foreach ($opt_label as $val => $lab) {
$list[] = $this->_build($val, $lab, $value, $disable);
}
$list[] = '</optgroup>';
} else {
$list[] = $this->_build($opt_value, $opt_label, $value, $disable);
}
}
// add the options to the xhtml and close the select
$xhtml .= implode("\n ", $list) . "\n</select>";
return $xhtml;
}
private function formatElementId($id)
{
// in here put whatever filter you want for the id value
$id = trim(strtr($id, array('[' => '-', ']' => '', ' ' => '', ':' => '')), '-');
$id = strtolower($id);
return $id;
}
}
Done. Create multi select element with a valid id.
<?php
$this->addElement('multiSelect', 'agente_id', array(
'label' => 'Label Name:',
'multiOptions' => array(
'' => 'Qualsiasi Agente',
'Agenti attivi: ' => array(
4 => 'Giovanni Verdi',
10 => 'Luigi Capoarea',
13 => 'Michela Passarin',
)
)
));
try this, it's works for me:
$select = new Zend_Form_Element_Select('select');
$options = Array(
'' => 'Qualsiasi Agente',
'agenti_attivi' => Array(
4 => 'Giovanni Verdi',
10 => 'Luigi Capoarea',
13 => 'Michela Passarin'
)
);
$this->addElements(array($xxxx,$select,$yyyy)); // $this : the form instance
and the result is:
<select id="select" name="select">
<option label="Qualsiasi Agente" value="">Qualsiasi Agente</option>
<optgroup label="agenti_attivi">
<option label="Giovanni Verdi" value="4">Giovanni Verdi</option>
<option label="Luigi Capoarea" value="10">Luigi Capoarea</option>
<option label="Michela Passarin" value="13">Michela Passarin</option>
</optgroup>
</select>
the problem is that the id attribute does not accept spaces and special special characters:
id="agente_id-optgroup-Agenti attivi: "
Zend is usually pretty good about rendering the proper html, given a doctype.
Try setting your doctype like this if you aren't already.
<?php
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->initView();
$viewRenderer->view->doctype('XHTML1_STRICT');
AND
<?php echo $this->doctype(); ?>
at the top of your layout
I don't have a install of ZF i can mess with easy, if this doesn't work ill setup a test environment.