i am trying to open the the accordion using external link..Actually there are three main accordions on the page(about,results,contact)
and there is a menubar with items(about,results,contact).
what i want is when i click on about menu item it should open the about accordion
the below is jquery code
$(function() {
$( "#accordion" ).accordion({
collapsible: true,
autoHeight: false ,
active: false,
navigation:true,
});
$(".exlnk").click(function(event){
window.location.hash=this.hash;
});
});
The below is html menubar code:
<div id="navmenu" style='z-index:9999;'>
<ul>
<li>About</li>
<li><a href="#" >Results</a></li>
<li>Contact</li>
</ul>
</div>
and below is jquery code for external link
<script>
$(document).ready(function(){
$('a.anchor_about').click(function(){
$("#accordion").accordion("activate", '<?php echo $_GET['id']; ?>');
return false;
});
});
</script>
but its not working..:(
anyone knows about same?
thanks in advance
EDIT1
<script>
$("#navmenu ul").children("li").click(function()
{
$("#accordion").accordion("activate", <?php echo (int)$_GET['id']; ?>);
});
EDIT2
Below is the accordion code
<div class="demo">
<div id="accordion"> <!--- main accordion 1 demo-->
<h3></h3>
<div id="accordion1" style="margin-bottom:17px;" >
<h1><a href="#" ></a></h1>
<div id="content_our_offer" > <!--- sub accordion 1 demo-->
<?php $page_id=1742;?>
<?php get_page( $page_id ) ;
$page_data = get_page( $page_id );
echo '<h3>'. $page_data->post_title .'</h3>';// echo the title
echo apply_filters('the_content', $page_data->post_content); ?>
</div>
<div style="margin-top:20px;"> <!--- sub accordion 2 demo-->
<h2 ><a href="#" ></a></h2> </div>
<div id="content_our_offer" >
<?php $page_id=1742;?>
<?php get_page( $page_id ) ;
$page_data = get_page( $page_id );
echo '<h3>'. $page_data->post_title .'</h3>';// echo the title
echo apply_filters('the_content', $page_data->post_content); ?>
</div>
</div>
<div style="margin-top:20px;">
<h6><a class="exlnk" href="#about" title="About" ></a></h6> </div> <!--- main accordion 2 demo-->
<div id="id_ourresults">
<?php
$directory = 'our_results';
try {
// Styling for images
foreach ( new DirectoryIterator("../" . $directory) as $item ) {
if ($item->isFile()) {
echo "<div class=\"expand_image\">";
$path = "/" . $directory . "/" . $item;
echo "<img src=\"" . $path . "\" width=861 height=443 />";
echo "</div>";
}
}
}
catch(Exception $e) {
echo 'No images found for this player.<br />';
}
?>
</div>
<div style="margin-top:20px;">
<h4></h4> </div> <!--- main accordion 3 demo-->
<div id="id_contactus">
<?php $page_id=1791 ;?>
<?php get_page( $page_id ) ;
$page_data = get_page( $page_id );
echo '<h3>'. $page_data->post_title .'</h3>';// echo the title
echo apply_filters('the_content', $page_data->post_content); ?>
</div>
</div>
</div><!-- End demo -->
$('a.anchor_about').click(function(){
$("#accordion").accordion("activate", '<?php echo $_GET['id']; ?>');
return false;
});
I don't think $_GET['id'] in the accordion activate line is going to work as I guess you want something like this
$('a.anchor_about').click(function(){
var sectionId = $(this).attr("href");
$("#accordion").accordion("activate", sectionId);
return false;
});
check if this works - if there are any errors let me know.
EDIT **
Also, I think to open accordion you need an index based value not a ID value like #someId (which works for tab for sure). The index is zero-based so that first section of accordion can be activated by passing a zero value, second with 1, and so on.
Give the menu items a name according to index
<div id="navmenu" style='z-index:9999;'>
<ul>
<li>About</li>
<li>Results</li>
<li>Contact</li>
</ul>
</div>
then activate the appropriate accordionitem with the index given in the menu items:
$("#navmenu ul").children("li").click(function()
{
$("#accordion").accordion("activate", $(this).attr("name"));
// ALSO POSSIBLE (name attribute not needed):
// Only if the menu items are in the same order as the accordion items
$("#accordion").accordion("activate", $(this).index());
});
Edit
I just figured your code is in a different file, so here's an option to minimize the change to your code. Seeing as you send a hash and GET the ID in a new page. The accordion needs an indexnumber, not an ID: Accordion Methods
<div id="navmenu" style='z-index:9999;'>
<ul>
<li>About</li>
<li>Results</li>
<li>Contact</li>
</ul>
</div>
$('#accordion').accordion({"active": $(window.location.hash).index()});
Related
I'm creating a menu for wordpress, but when I click on the permalink the content stays the same. And my second dropdown does not work eather. The problem is that on my section where the content needs to be it not shows. The content just takes the last message and not the post i select on the menu.
https://i.gyazo.com/1698056c27baa40768659d2edab5e3d9.png
This is how it stays even if i click an other post.
<?php
get_header();
?>
<div class="menu">
<div>
<h1>Documentatie</h1>
</div>
<?php $cats = get_categories();
foreach ($cats as $cat) {
$cat_id= $cat->term_id;
echo "<div class='dropdown'>";
echo "<button onclick='myFunction()' class='dropbtn'>".$cat->name."</button>";
echo "<div id='myDropdown' class='dropdown-content'>";
query_posts("cat=$cat_id&post_per_page=100");
if (have_posts()) : while (have_posts()) : the_post(); ?>
<button class="dropbutton"><h2><?php the_title(); ?></h2></button>
<?php endwhile;
?>
</div>
</div>
<?php
else :
echo "<p>Geen content gevonden</p>";
endif;
wp_reset_postdata();
}
?>
</div>
<div class="content">
<h2><?php the_title(); ?></h2>
<div class="wpcontent"><?php the_content(); ?> </div>
</div>
<?php wp_footer(); ?>
<script>
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
</script>
Have a look at my other 2 comments and proposed solution below, this is not a WP issue you're facing, it's JS/jQuery
echo "<div class='dropdown'>";
echo "<button onclick='myFunction(" . $cat->slug . ")' class='dropbtn btn-" . $cat->slug . "'>".$cat->name."</button>";
echo "<div id='myDropdown' class='dropdown-content'>";
And:
function myFunction(cat_slug) {
$('.btn-' + cat_slug).show();
}
Try that, should work :)
I am displaying data from database which is linked to CMS. The problem I get is data from only one of my tabs is being displayed. Suppose I have two tabs, Tab 1, Tab 2. Instead of Tab 1 being active, Tab 2 is active and data is displayed of Tab 2. But, when I click on Tab 1, no data with respect to Tab 1 is displayed. The same data is present i.e Tab 2 data.
I am using mapping to get the ids of respective Tab.
<ul class="tabs" data-tab>
<?php
if(isset($X['list_by_parent_id'][0]) && !empty($X['list_by_parent_id'][0]))
{
$top_category_index=1;
foreach ($X['list_by_parent_id'][0] as $category_id)
{
?>
<li class="tab-title <?php if($top_category_index==1){ echo "active"; }?>"><?php echo $SITE['tmp']['product_categories'][$category_id] ?></li>
<?php
}
}
?>
</ul>
X is a global variable which is an array and stores everything.
This is the code that does mapping and displays the content.
<div class="category-content">
<div class="menu-cat-content tabs-content">
<?php if(isset($SITE['category_list_by_parent_id'][0]) && !empty($SITE['category_list_by_parent_id'][0]))
{
$top_category_index_mapped=1;
foreach ($SITE['category_list_by_parent_id'][0] as $category_id)
{ ?>
<div id="category-<?php echo $top_category_index_mapped; ?>" class="content <?php if($top_category_index_mapped++==1) { ?>active<?php } ?>">
//code for content
</div>
Rendered HTML:
<div class="category-content">
<div class="menu-cat-content tabs-content">
<div id="category-1" class="content active">
<!--sub category 1-->
</div><!--sub-category-clearfix2-->
<!--sub category 2 ends-->
</div> <!--category-div, index_mapped -->
<div id="category-2" class="content active">
<!--sub category 1-->
</div><!--sub-category-clearfix2-->
<!--sub category 2 ends-->
</div> <!--category-div, index_mapped -->
<div id="category-3" class="content active">
EDIT: I saw that top_category_index_mapped was set to 1 in category-*top_category_index_mapped. I replaced it and rendered html now looks like this.
This line:
$top_category_index=1;
sets the $top_category_index to 1 for the first tab. This line:
<li class="tab-title <?php if($top_category_index==1){ echo "active"; }?>
is equal to this the firs two times:
<li class="tab-title active">
because of the properties of the ++ operator. Read more here.
For example:
$a = 5;
echo "Should be 5: " . $a++ . "<br />\n";
echo "Should be 6: " . $a . "<br />\n";
Since you've only tested with two tabs it seems, that's why you are getting those results. It might also be helpful to include the rendered html.
Sir, I have a main menu rendered in page.tpl.php
<div class="menu_wrapper">
<nav id="main-menu" role="navigation">
<a class="nav-toggle" href="#">Navigation</a>
<div class="menu-navigation-container">
<?php print drupal_render($main_menu_tree); ?>
<div class="clear"></div>
</nav>
In which here rendered main_menu_tree, i want to replace this page with my superfish menu.
Use block_load as follows, replace
<?php print drupal_render($main_menu_tree); ?>
with
<?php
$block = block_load('superfish', 1);
$output = render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;
?>
My problem is that I am trying to create a javascript menu but the script seems to be loading really slow and late so it's not working on the first seconds. Correct me if I am wrong.
Second, I don't manage to make each column to work well and sometimes it's just linking to the same page, no matter which option I choose as well to another problem that there is no reaction to my choice, like I didn't do anything even if I really chose something from the menu.
Do you know what can be the problem? Is it a bad idea to do it with JavaScript? Would you make it with PHP? I also thing that the code is maybe too long.
This is the example for my problem - link
<div class="quick_width">
<div class="quick_links"><img src="http://www.101greatgoals.com/wp-content/themes/tutorial/images/quick_links.jpg" width="102" height="37" alt=" "></div>
<div class="green_bg">
<div class="option_width">
<div class="form_row_name_input1">
<ul class="dropdownul">
<li id="categories">
<?php wp_dropdown_categories('show_option_none=Country'); ?>
<script type="text/javascript"><!--
var dropdown = document.getElementById("cat");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "<?php echo get_option('home');
?>/category/goals/"+dropdown.options[dropdown.selectedIndex].text.split(' ').join('-');
}
}
dropdown.onchange = onCatChange;
--></script>
</li>
</ul>
</div>
<div class="form_row_name_input1">
<ul class="dropdownul">
<li id="categories">
<?php wp_dropdown_categories('taxonomy=teams&show_option_none=Teams&name=teamsmenu'); ?>
<script type="text/javascript"><!--
var dropdown = document.getElementById("teamsmenu");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "<?php echo get_option('home');
?>/?teams="+dropdown.options[dropdown.selectedIndex].text.split(' ').join('-');
}
}
dropdown.onchange = onCatChange;
--></script>
</li>
</ul>
</div>
<div class="form_row_name_input1">
<ul class="dropdownul">
<li id="categories">
<?php wp_dropdown_categories('taxonomy=players&show_option_none=Players&name=playersmenu'); ?>
<script type="text/javascript"><!--
var dropdown = document.getElementById("playersmenu");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "<?php echo get_option('home');
?>/?players="+dropdown.options[dropdown.selectedIndex].text.split(' ').join('-');
}
}
dropdown.onchange = onCatChange;
--></script>
</li>
</ul>
</div>
<div class="form_row_name_input1">
<ul class="dropdownul">
<li id="categories">
<?php wp_dropdown_categories('taxonomy=managers&show_option_none=Managers&name=managersmenu'); ?>
<script type="text/javascript"><!--
var dropdown = document.getElementById("managersmenu");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "<?php echo get_option('home');
?>/?managers="+dropdown.options[dropdown.selectedIndex].text.split(' ').join('-');
}
}
dropdown.onchange = onCatChange;
--></script>
</li>
</ul>
</div>
<div class="form_row_name_input1">
<ul class="dropdownul">
<li id="categories">
<?php wp_dropdown_categories('taxonomy=clean_feeds&show_option_none=Other&name=othermenu'); ?>
<script type="text/javascript"><!--
var dropdown = document.getElementById("othermenu");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "<?php echo get_option('home');
?>/?clean_feeds="+dropdown.options[dropdown.selectedIndex].text.split(' ').join('-');
}
}
dropdown.onchange = onCatChange;
--></script>
</li>
</ul>
</div>
</div>
</div>
<div class="right_align"></div>
</div>
In this case, I would definitely recommend creating the HTML output through PHP beforehand. This way, when the page has loaded you can trigger your menu-script.
The example provided in the WordPress reference for the wp_dropdown_categories() function has a cool example which should help you on your way. What it does is basically replace certain parts of the generated HTML. These replacements in your case would then be mainly in the generated URL. Example reproduced here for clarity:
<li id="categories">
<h2><?php _e('Posts by Category'); ?></h2>
<form action="<?php bloginfo('url'); ?>/" method="get">
<div>
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript><div><input type="submit" value="View" /></div></noscript>
</div></form>
</li>
I have made a forum and I want the user to delete their comment if they don't want it.
Now it deletes the first post and not the post that they have clicked "delete" on.
How can I check that its the comment they click on that gets deleted?
I have made this:
$(function() {
$(".slet").click( function(event) {
event.preventDefault();
//$(this).css("background-color","#000");
var id = "<?=$deleteID?>";
//alert(id);
$("#forum_content").fadeOut();
});
});
and my php:
it is a little messy.
<?php foreach ($comments as $comment): ?>
<?php
if($comment->level == "admin")
{
echo '<div class="adminclass">';
}
?>
<div id="forum_content" class="content">
<div class="forum_comment">
<div class="forum_profil_img"><img width="90" height="90" src="<?php echo base_url();?>images/users/thumbs/<?php echo $query->profile_picture; ?>"></div><!-- forum_profil_img -->
<div class="forum_post_content">
<span class="post_navn"><?php echo anchor('profil/index/'.$comment->kommentar_brugernavn, $comment->kommentar_brugernavn); ?></span>
<span style="font-size:11px; margin-left:3px; color:#686868;"><i> Siger</i></span><br>
<div id="data"><?php echo nl2br($comment->indhold); ?></div><!-- data -->
</div><!-- forum_post_content -->
<div style="width:auto; float:right; color:#a0a0a0; clear:left; position:relative; bottom:-15px;" id="forum_dato">
<i>
<abbr class="timeago" title="<?php echo $comment->dato; ?>"><?php echo $comment->dato; ?></abbr>
<?php
if($this->session->userdata('logget_ind') == 1 &&
$this->session->userdata('username') == $comment->brugernavn &&
time() - $comment->time < 300)
{ echo "- <a href=''>Ret</a> - <a class='slet' href=''>Slet</a>";
$deleteID = $comment->commentID;
} ?>
</i>
</div><!-- forum_post_content -->
</div><!-- forum_comment -->
<?php if ($comment->level == "admin") { ?> <span class="admin-ribbon"></span></div> <?php } ?>
</div><!-- content -->
<?php endforeach ?>
On each page use a counter, on which you assign a unique id to each comment from as it's added. That way you can delete comments irrelevant of their order (original or ordered).
Change the line echo "- <a href=''>Ret</a> - <a class='slet' href=''>Slet</a>" to
echo "- <a href=''>Ret</a> - <a class='slet' id='slet-".$comment->commentID."' href=''>Slet</a>"
and the click handler to:
$(function() {
$(".slet").click( function(event) {
event.preventDefault();
//$(this).css("background-color","#000");
var id = $(this).attr("id").replace(/[^0-9]/g, "");
alert(id);
$("#forum_content").fadeOut();
});
});