• Resolved zed28

    (@zed28)


    I have page, let′s call it “Special Terms Glossary”.

    It contains a list of Special Terms, divided into sections by first letters, each section has “heading panel” with clickable letters, for example:

    A B C D E F G …
    “List of all terms starting with letter E”

    I know how to move user to corresponding page section using anchors, for example if user click letter “D”, page will roll to “D section”, and there will be “heading panel”:

    A B C D E F G …
    “List of all terms starting with letter D”

    My question is: how to highlight corresponding letters in “heading panel” automatically, without styling each one “heading pannel”.

    Is it possible?

    Alex

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator cubecolour

    (@numeeja)

    Can you provide a link to the page where this can be seen?

    Thread Starter zed28

    (@zed28)

    Moderator cubecolour

    (@numeeja)

    You have an ‘alphabet’ heading panel above each letter’s section with the corresponding letter of the section already highlighted in each panel. Can you explain how what it is that you wish to change?

    Thread Starter zed28

    (@zed28)

    Sorry, my fault.
    It is not my site, I want to create something like this.

    Moderator cubecolour

    (@numeeja)

    OK that makes sense.

    It looks like those lists of links are just created as static html with a span around the highlighted letter for each.

    Some css rules targeting the class of the span would be used to make those letters bigger.

    It might be better to use a floating panel with just a single list of links.

    Can you link to the page on your site where you wish to use this?

    Thread Starter zed28

    (@zed28)

    I have my site on localhost just now.

    Floating panel seems to be perfect solution. Can you give me some basic ideas for it, please?

    Many thanks from Alex

    Moderator cubecolour

    (@numeeja)

    OK I have come up with something (on my localhost) this is quite basic, so might need a bit of tweaking.

    So add a menu – this could be made using a simple shortcode function in your child theme’s functions.php or a plugin, or just put the markup in the page

    <ul class="alphabetmenu">
      <li><a href="#alink">a</a></li>
      <li><a href="#blink">b</a></li>
      <li><a href="#clink">c</a></li>
      <li><a href="#dlink">d</a></li>
      <li><a href="#elink">e</a></li>
      <li><a href="#flink">f</a></li>
    </ul>

    Add some css to the child theme’s sylesheet to style it as a horizontal menu

    .alphabetmenu {
    	clear: both;
    	list-style: none;
    	width: 100%;
    	padding: 4px;
    	position: fixed;
    	top: 20px;
    	left: 50%;
    }
    
    .alphabetmenu li {
    	display: block;
    	float: left;
    }
    
    .alphabetmenu li a {
    	color: #fff;
    	background-color: #900;
    	color: #fff;
    	padding: 10px;
    	margin: 0 2px;
    	width: 40px;
    	text-align: center;
    }
    .alphabetmenu li.active a {
    	background-color: #009;
    }
    
    .alphabetmenu li a:hover {
    	color: #fff;
    	background-color: #090;
    }

    Make a folder called js in your child theme and create a new file inside that called alphabetmenu.js

    Add the following code into that file:

    jQuery(document).ready(function($) {
    	$('.alphabetmenu li').on('click', function(){
    		$(this).addClass('active').siblings().removeClass('active');
    	});
    });

    Add the following code into the child theme’s functions.php to register & enqueue the script

    //* Register and Enqueue alphabet menu script
    function alphabetmenu_script() {
    	wp_register_script( 'alphabetmenu', get_stylesheet_directory_uri() . '/js/alphabetmenu.js', array( 'jquery' ), '1.0.0', false );
    	wp_enqueue_script( 'alphabetmenu' );
     }
    
    add_action('wp_enqueue_scripts', 'alphabetmenu_script');

    What this should do is add a new class called ‘active’ to a menu item when it is clicked. Then when one of the other menu items is clicked it will remove the class and apply it to the latest menu item to have been clicked.

    Thread Starter zed28

    (@zed28)

    Many thanks, this is perfect!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Dynamic heading panel with anchors’ is closed to new replies.