I'm trying to call different divs to show or hide, when I click on a hyperlink with a class. The problem is, I can't get one to disappear when the other hyperlink is clicked. I know its in .Toggle, but I can't figure out how to do it. Thanks for your help in advance.
HTML:
<div class="menu-container">
<div class="left">
<?php if (have_rows('menu_items')):
while (have_rows('menu_items')): the_row(); ?>
<div id="<?php the_sub_field('menu_id'); ?>" class="menu-item"><?php the_sub_field('menu_item'); ?></div>
<?php endwhile;
endif; ?>
</div>
<div class="food-container">
<?php if (have_rows('food_items')):
while (have_rows('food_items')): the_row(); ?>
<div id ="<?php the_sub_field('food_id'); ?>">
<div class="food-item-container">
<div class="food"> <h3><?php the_sub_field('food_name'); ?></h3>
<?php the_sub_field('food_description'); ?>
</div><div class="price"><?php the_sub_field('price'); ?></div>
</div>
<div class="clear"></div>
<?php endwhile;
endif; ?>
</div>
Javascript:
<script>
$(document).ready(
function() {
$("#menu-item1").click(function() {
$("#food_id1_1, #food_id1_2, #food_id1_3, #food_id1_4, #food_id1_5, #food_id1_6").fadeToggle();
});
$("#menu-item2").click(function() {
$("#food_id2_1, #food_id2_2, #food_id2_3, #food_id2_4, #food_id2_5, #food_id2_6").fadeToggle();
});
});
</script>
Here is the url ---> http://dev.the-end-zone.com/menu/
I believe you want to toggle individual menu items as well as when the other is toggled you want to hide the previous menu items if they were open
You can do something like this:
Sample HTML:
<a id="a1" href="javascript:;">CLick 1</a>
<div id="f1" class='fdiv'>F1</div>
<br/>
<a id="a2" href="javascript:;">CLick 2</a>
<div id="f2" class='fdiv'>F2</div>
jQuery:
$(document).ready(function(){
$("#a1").click(function(){
$("#f2").hide();
$("#f1").toggle();
});
$("#a2").click(function(){
$("#f1").hide();
$("#f2").toggle();
});
});
https://jsfiddle.net/sandenay/L06LtLfz/
Related
I have setup a small webstore and I want to show this <div class ="data-plan"></div> only for one single product. My database table from where I want to match this id is called sb_files and it has these fields id table_id path type slide_link, so I am trying to get my code to go trough that table, search up the id ( Its 13040100 ) and if it matches then to show the div, else it shows an empty div. I am using the Yii2 framework, which is php based. So far I have tried this
<?php if($product->$this->id('13040100')): ?>
<ul>
<?php
$index = 1;
foreach($product->() as $prd):
if(strpos($prd->getPath(), '13040100') == true) {
?>
<div class="wrap">
<div class="data-plan" style="height:20px; width:65px; background-color:#00a651; float:right;color:white;margin:10px;text-align:center;">A+++ </div>
<div class="data-plan" style="height:20px; width:65px; background-color:#ed1c1c; float:right;color:white;margin:10px;">Datu lapa </div>
</div>
<?php
$index++;
}
endforeach;
?>
</ul>
<?php else: ?>
<div class="wrap">
</div>
<?php endif; ?>
I'm not that familiar with Yii2 framework myself, but are you sure that $product->$this->id('13040100') is correct? It looks weird to me, shouldn't it be something like $product->id('13040100')?
The solution was way easier than I tought, just had to think simple
<?php if ($product->id == '13001100'): ?>
<div class="wrap">
<div class="data-plan" style="height:20px; width:65px; background-color:#00a651; float:right;color:white;margin:10px;text-align:center;">A+++ </div>"
<div class="data-plan" style="height:20px; width:65px; background-color:#ed1c1c; float:right;color:white;margin:10px;">Datu lapa </div>
</div>
<?php else: ?>
<div class="wrap">
</div>
<?php endif;
I have a dropdown switcher in order to change storeviews. I would like to implement a function done with PHP once an option from the dropdown is clicked.
I have been trying to implement this event via Jquery as below:
<?php if (count($block->getGroups()) > 1): ?>
<div class="switcher store switcher-store" id="switcher-store">
<strong class="label switcher-label"><span><?php /* #escapeNotVerified */
echo __('Select Store') ?></span></strong>
<div class="actions dropdown options switcher-options">
<?php foreach ($block->getGroups() as $_group): ?>
<?php if ($_group->getId() == $block->getCurrentGroupId()): ?>
<div class="action toggle switcher-trigger"
role="button"
tabindex="0"
data-mage-init='{"dropdown":{}}'
data-toggle="dropdown"
data-trigger-keypress-button="true"
id="switcher-store-trigger">
<strong>
<span><?php echo $block->escapeHtml($_group->getName()) ?></span>
</strong>
</div>
<?php endif; ?>
<?php endforeach; ?>
<ul class="dropdown switcher-dropdown" data-target="dropdown">
<?php foreach ($block->getGroups() as $_group): ?>
<?php if (!($_group->getId() == $block->getCurrentGroupId())): ?>
<li class="switcher-option">
<a href="#" data-post='<?= $block->getTargetStorePostData($_group->getDefaultStore()); ?>'>
<?php echo $block->escapeHtml($_group->getName()) ?>
</a>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif; ?>
<script>
require(['jquery', 'jquery/ui'], function($){
$("#switcher-option").trigger("click", clickConfirm());
function clickConfirm(){
var isGood=confirm('You will lose your cart items if you switch between seasons!');
if (isGood) {
<?php $seasonsHelper->getClearCart(); ?>
} else {
<?php $this->getUrl('*');?>
}
}
});
</script>
The store change works perfectly, but the confirm event appears on different places, not only when I select the dropdown button. If I add to cart, it also appears, when I load the page, It also appears.
I've been trying to accurate identifier with ".class" or "#id" but nothing works.
Is this the proper way to do it?
You need to make some changes to your JS code:
require(['jquery', 'jquery/ui'], function($){
if( $("#switcher-option").lengh>0 ){ /// check for element existance
$("#switcher-option").trigger("click", clickConfirm());
}
function clickConfirm(){
var isGood=confirm('You will lose your cart items if you switch between seasons!');
if (isGood) {
<?php $seasonsHelper->getClearCart(); ?>
} else {
<?php $this->getUrl('*');?>
}
}
});
Note: code is not tested, just shared the logic.
I've overwritten the "blog.php", for Category Blog to put the AddThis social media sharing plugin at the bottom of each article. Working on joomla 3.0
The Category blog layout displays many articles per page. By default AddThis uses your current page to share/like/tweet/etc.
My add this code looks like this:
<div class="article-sharing">
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=undefined"></script>
<!-- AddThis Button END -->
</div>
What I of course want is to change the URL being used to the corresponding article. This is possible (http://support.addthis.com/customer/portal/articles/381242-url-title#.Ucd1HevmT2x).
The code should look like this (only with dynamic urls):
<div class="article-sharing">
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style"
addthis:url="http://example.com/blog/my-article-about-horses"
addthis:title="The title of my article"
addthis:description="The short article description">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=undefined"></script>
<!-- AddThis Button END -->
</div>
Would be great if someone could help me understand a bit better how I go about doing this.
addthis:url="http://example.com/blog/my-article-about-horses"
addthis:title="The title of my article"
addthis:description="The short article description"
Here is the full blog.php code.
<?php
/**
* #package Joomla.Site
* #subpackage com_content
*
* #copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers');
JHtml::_('behavior.caption');
?>
<div class="blog<?php echo $this->pageclass_sfx;?>">
<?php if ($this->params->get('show_page_heading', 1)) : ?>
<div class="page-header">
<h1> <?php echo $this->escape($this->params->get('page_heading')); ?> </h1>
</div>
<?php endif; ?>
<?php if ($this->params->get('show_category_title', 1) or $this->params->get('page_subheading')) : ?>
<h2> <?php echo $this->escape($this->params->get('page_subheading')); ?>
<?php if ($this->params->get('show_category_title')) : ?>
<span class="subheading-category"><?php echo $this->category->title;?></span>
<?php endif; ?>
</h2>
<?php endif; ?>
<?php if ($this->params->get('show_description', 1) || $this->params->def('show_description_image', 1)) : ?>
<div class="category-desc">
<?php if ($this->params->get('show_description_image') && $this->category->getParams()->get('image')) : ?>
<img src="<?php echo $this->category->getParams()->get('image'); ?>"/>
<?php endif; ?>
<?php if ($this->params->get('show_description') && $this->category->description) : ?>
<?php echo JHtml::_('content.prepare', $this->category->description, '', 'com_content.category'); ?>
<?php endif; ?>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php $leadingcount = 0; ?>
<?php if (!empty($this->lead_items)) : ?>
<div class="items-leading">
<?php foreach ($this->lead_items as &$item) : ?>
<div class="leading-article leading-<?php echo $leadingcount; ?><?php echo $item->state == 0 ? ' system-unpublished' : null; ?>">
<?php
$this->item = &$item;
echo $this->loadTemplate('item');
?>
</div>
<div class="clearfix"></div>
<?php
$leadingcount++;
?>
<div class="article-sharing">
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style"
addthis:url="http://example.com"
addthis:title="An Example Title"
addthis:description="An Example Description">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=undefined"></script>
<!-- AddThis Button END -->
</div>
<?php endforeach; ?>
</div><!-- end items-leading -->
<div class="clearfix"></div>
<?php endif; ?>
<?php
$introcount = (count($this->intro_items));
$counter = 0;
?>
<?php if (!empty($this->intro_items)) : ?>
<?php foreach ($this->intro_items as $key => &$item) : ?>
<?php
$key = ($key - $leadingcount) + 1;
$rowcount = (((int) $key - 1) % (int) $this->columns) + 1;
$row = $counter / $this->columns;
if ($rowcount == 1) : ?>
<div class="items-row cols-<?php echo (int) $this->columns;?> <?php echo 'row-'.$row; ?> row-fluid">
<?php endif; ?>
<div class="span<?php echo round((12 / $this->columns));?>">
<div class="item column-<?php echo $rowcount;?><?php echo $item->state == 0 ? ' system-unpublished' : null; ?>">
<?php
$this->item = &$item;
echo $this->loadTemplate('item');
?>
<div class="article-sharing">
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=undefined"></script>
<!-- AddThis Button END -->
</div>
</div><!-- end item -->
<?php $counter++; ?>
</div><!-- end spann -->
<?php if (($rowcount == $this->columns) or ($counter == $introcount)): ?>
</div><!-- end row -->
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!empty($this->link_items)) : ?>
<div class="items-more older-articles">
<?php echo $this->loadTemplate('links'); ?>
</div>
<?php endif; ?>
<?php if (!empty($this->children[$this->category->id])&& $this->maxLevel != 0) : ?>
<div class="cat-children">
<h3> <?php echo JTEXT::_('JGLOBAL_SUBCATEGORIES'); ?> </h3>
<?php echo $this->loadTemplate('children'); ?> </div>
<?php endif; ?>
<?php if (($this->params->def('show_pagination', 1) == 1 || ($this->params->get('show_pagination') == 2)) && ($this->pagination->get('pages.total') > 1)) : ?>
<div class="pagination">
<?php if ($this->params->def('show_pagination_results', 1)) : ?>
<!-- <p class="counter pull-right hidden-phone"> <?php echo $this->pagination->getPagesCounter(); ?> </p> -->
<?php endif; ?>
<?php echo $this->pagination->getPagesLinks(); ?> </div>
<?php endif; ?>
</div>
Update
Thank you Ahmad for your answer. It helped out a lot.
This is my current AddThis code within the blog_item.php file. It works well for Twitter, email etc. But I have some issues when it comes to Facebook. The "addthis:title" and description are being not being used. Instead the OG tags I have in the index.php file are being used. It still links to the correct article when the shared link is clicked on Facebook. This can be a bit confusing for the user - when he/she get's the Facebook share pop-up there is nothing about the article that he/she wants to share - only info about the page in general.
<div class="article-sharing">
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style"
addthis:url="http://www.tolt-inspiration.com<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>"
addthis:title="<?php echo $this->escape($this->item->title); ?>"
addthis:description="<?php echo $this->escape($this->item->metadesc); ?>">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"
addthis:title="<?php echo $this->escape($this->item->title); ?>"
addthis:description="<?php echo $this->escape($this->item->metadesc); ?>"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<!-- AddThis Button END -->
</div>
How to fix that?
Note on editing core files
First of all let's clarify that editing Joomla's core file is a bad practice. You should always use overrides. This way you make sure that your changes wont get overwritten when Joomla is updated.
update: didn't notice the question title saying that OP is working on override already.
How Joomla category view is rendered
Let's dissect the category view in Joomla (in order of execution). It starts with default.php (mother of all views) Then either loads:
blog.php (for blog view; obviously) This part output the category description, image, title, columns ... etc and will call the following parts:
blog_item.php -- display the article <- This is the file you should be working on.
blog_links.php
default_items.php (for list view)
For Joomla 1.5 before <span class="article_separator"> </span> add the code
For Joomla 2.5 before <div class="item-separator"></div> add the code
The code
<div class="article-sharing">
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style"
addthis:url="<?php echo $this->item->readmore_link; ?>"
addthis:title="<?php echo $this->escape($this->item->title); ?>"
addthis:description="<?php echo $this->escape($this->item->metadesc); ?>">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
Adding the <script>
Note that now we didn't add addthis <script> yet. You don't want to be adding it to blog_item.php or it will be added multiple times. We will add it to blog.php. To add it using Joomla's API:
Right after:
defined('_JEXEC') or die('Restricted access');
Add:
$doc =& JFactory::getDocument();
$doc->addScript("//s7.addthis.com/js/300/addthis_widget.js#pubid=undefined");
Note
Adding the script using the addScript method is not required but it is preferred than just adding it simply in the template. Some plugins for example move every script tag right before closing the body tag; It provides a way to grasp that object.
I have this code that prints out up to 4 service providers. once clicked, the box expands and shows the rest if there are more. What i am trying to do is if there are more than 4 entries, to print a More link so users know to click for more. I also need the More button to disappear when click and reappear when reclicked.
Can anyone help me. This is driving me crazy
Thank you for your help ahead of time.
<?php
/**
* #file
*/
?>
<head>
<script>
var remove=function(){
$('#ID_OF_BUTTON').hide(500);
}
</script>
</head>
<div class="cloud-computing-item">
<div class="container">
<div class="item-header">
<h3> <?php print $company['name'] ?> </h3>
</div>
<div class="item-subheader">
<div class="label">Services Offered:</div>
<div class="data service-offerings">
<?php
foreach($company['services_display'] as $service => $element){
print $element;
}
?>
</div>
</div>
<div class="item-body">
<div class="overview">
<div class="label">Cloud Providers:</div>
<div class="data">
<?php
//limit shown entries upto 4
foreach(array_slice($company['service_providers'], 0, 4) as $provider): ?>
<div>
<?php print $provider; ?>
</div>
<?php endforeach; ?>
<div id="show"style="color:#000099;font-weight:bold; margin-bottom:-13px;"></div>
<!--<div id="show"style="color:#000099;font-weight:bold; margin-bottom:-13px;"><a onclick="remove(); return true;">More</a></div>
<div id="hide"style="color:#000099;font-weight:bold; margin-bottom:-12px; display: none;"><a onclick="add(); return true;">Hide</a></div> -->
</div>
</div>
<div class="details">
<?php
// if entries are greater then 4, show the rest
foreach(array_slice($company['service_providers'], 4) as $provider): ?>
<div>
<?php
print $provider;
?>
</div>
<?php endforeach; ?>
<?php print theme('cloud_computing_item_details', array('company' => $company)); ?>
</div>
</div>
<div style="clear: both; height: 5px;"> </div>
</div>
</div>
So, try this modification:
<div class="label">Cloud Providers:</div>
<div class="data">
<?php $i = 0; ?>
<?php foreach($company['service_providers'] as $provider): ?>
<div<?php echo ($i > 3) ? ' class="hide"' : ''; ?>><?php print $provider; ?></div>
<?php $i++; ?>
<?php endforeach; ?>
<?php if(count($company['service_providers']) > 4):?>
<div class="show-more" style="color:#000099;font-weight:bold; margin-bottom:-13px;">Show More</div>
<?php endif; ?>
</div>
Now let's assume You are using jQuery add this:
<script type="text/javascript">
$(document).ready(function(
$('.hide').hide(); // this will hide all the elements with the class 'hide'
$('.show-more').live('click', function(){
var parent = $(this).parent();
parent.find('.hide').show().removeClass('hide').addClass('show');
$(this).text('Show Less').removeClass('show-more').addClass('show-less');
});
$('.show-less').live('click', function(){
var parent = $(this).parent();
parent.find('.show').hide().removeClass('show').addClass('hide');
$(this).text('Show Less').removeClass('show-less').addClass('show-more');
});
){});
</script>
Use function on instead of live if You are using jQuery higher then 1.7.
Fiddle: http://jsfiddle.net/eznnC/ (though the hiding is not working but I believe it will in normal environment).
the first part to make only the 4 or more show a More link is below. the link doesn't disappear at the moment nor does it reappear.
<?php
//limit shown entries upto 4
foreach(array_slice($company['service_providers'], 0, 4) as $provider): ?>
<div>
<?php print $provider; ?>
</div>
<?php endforeach; ?>
<?php
// shows a More link for companies with more than for providers
foreach(array_slice($company['service_providers'], 4, 1) as $provider): ?>
<div>
<div id="more" style="color:#000099;font-weight:bold; margin-bottom:-13px;">
<?php print ('<a onclick="">More</a>'); ?>
</div>
</div>
<?php endforeach; ?>
I am creating some jQuery functionality on my website whereas an array of Facebook posts and Tweets is looped through to show on the front page.
I have 5 boxes on my front page which I need 5 to show random elements from this array at the same time, then I using some jQuery cycle functionality to cycle through this array. The only issue is, as I am looping over this array 5 times (with each box) and there are only 20 items in this array it can show repeated data.
To help explain this more here is my code:
<?php
$social_feeds = array_merge($tweets_feed, $facebook_feeds);
$social_feeds_arranged = $tweets_feed_instance->sortArrayItemsByDate($social_feeds);
?>
<div id="social_box_item1" class="social_box_item">
<?php foreach($social_feeds_arranged as $item) { ?>
<a class="item">
<?php echo $item['text'] ?>
</a>
<?php } ?>
</div>
<div id="social_box_item2" class="social_box_item">
<?php foreach($social_feeds_arranged as $item) { ?>
<a class="item">
<?php echo $item['text'] ?>
</a>
<?php } ?>
</div>
<div id="social_box_item3" class="social_box_item">
<?php foreach($social_feeds_arranged as $item) { ?>
<a class="item">
<?php echo $item['text'] ?>
</a>
<?php } ?>
</div>
<div id="social_box_item4" class="social_box_item">
<?php foreach($social_feeds_arranged as $item) { ?>
<a class="item">
<?php echo $item['text'] ?>
</a>
<?php } ?>
</div>
<div id="social_box_item5" class="social_box_item">
<?php foreach($social_feeds_arranged as $item) { ?>
<a class="item">
<?php echo $item['text'] ?>
</a>
<?php } ?>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#social_box_item1').cycle({
});
jQuery('#social_box_item2').cycle({
});
jQuery('#social_box_item3').cycle({
});
jQuery('#social_box_item4').cycle({
});
jQuery('#social_box_item5').cycle({
});
});
</script>
What I need to happen I think is for the first loop to push the item it is displaying ot the back of the array, so when the second loop accesses the first item it will not show the same array item, the same with the 3rd, 4th and 5th loops. I have attempted to do this using array_push and array_shift but can't seem to get it working.
Does anybody have any ideas or can help point out where I am going wrong?
Those loops are not needed then. You can access those array items one by one, if you meant that. Try this:
$social_feeds = array_merge($tweets_feed, $facebook_feeds);
$social_feeds_arranged = $tweets_feed_instance->sortArrayItemsByDate($social_feeds);
?>
<div id="social_box_item1" class="social_box_item">
<a class="item">
<?php echo $social_feeds_arranged[0]['text']; ?>
</a>
</div>
<div id="social_box_item2" class="social_box_item">
<a class="item">
<?php echo $social_feeds_arranged[1]['text']; ?>
</a>
</div>
<div id="social_box_item3" class="social_box_item">
<a class="item">
<?php echo $social_feeds_arranged[2]['text']; ?>
</a>
</div>
<div id="social_box_item4" class="social_box_item">
<a class="item">
<?php echo $social_feeds_arranged[3]['text']; ?>
</a>
</div>
<div id="social_box_item5" class="social_box_item">
<a class="item">
<?php echo $social_feeds_arranged[4]['text']; ?>
</a>
</div>