Introduce yourself here! In order to avoid spam, new users must first comment on the discussion in the 'Introductions' before they become 'full members'
Anker Plugin / Several static pages shown in one static page?
  • I would like to create a glossary but also be able to link to every individual word in the glossary.

    Is there a plugin to creat ankers to link to special part in a static page?

    Another solution would some kind of a static page with cointains the content of several other static pages. Is this possible?

  • Hi, both are possible, but I don't think a plugin exists.
    You could do it manually in HTML, but it is quite long to do.
    Otherwise you could create a new BBTag, quite easy to do.

    Something like this (not tested, based on my Internal URLs):

    <?php
    /*
    Plugin Name: Glossary Item
    Plugin URI: http://www.flatpress.org/vanilla2/discussion/3004/anker-plugin-several-static-pages-shown-in-one-static-page#Item_2
    Description: Create a glossary item.
    Author: Piero VDFN
    Version: 1.0
    Author URI: http://www.pierovdfn.it/
    */

    class Plugin_Glossitem {

    /**
    * List of already used anchors (used to avoid duplicates).
    */
    private $used = array();

    /**
    * The constructor. Set hook.
    */
    public function __construct()
    {
    add_filter('bbcode_init', array(&$this, 'setTags'), 10, 1);
    }

    /**
    * Tells the BBCode plugin about the tags of this plugin.
    *
    * @param object $bbcode: The BBCode instance
    * @return object: The first parameter
    */
    public function setTags($bbcode)
    {
    $bbcode->addCode(
    'glossitem',
    'callback_replace',
    array(&$this, 'doTag'),
    array(
    'usecontent_param' => array('default')
    ),
    'link',
    array(
    'listitem', 'block', 'inline'
    ),
    array('link')
    );
    $bbcode->setCodeFlag('glossitem', 'closetag', BBCODE_CLOSETAG_MUSTEXIST);
    return $bbcode;
    }

    /**
    * Handle the tag.
    *
    * @param string $action: The action to do
    * @param array $attributes: The attributes of the tag
    * @param string $content: The tag content
    * @param ??? $params: Unknown
    * @param ??? $node_object: Unknown
    */
    public function doTag($action, $attributes, $content, $params, $node_object)
    {
    if(!empty($attributes['default'])) {
    $id = $attributes['default'];
    } else {
    // Remove illegal characters, should automatically escape HTML
    $sanitized = sanitize_title($content);
    $id = $sanitized;

    // Avoid duplicates
    $i = 1;
    while(in_array($id, $this->used)) {
    $id = $sanitized . '-' . $i;
    $i++;
    }
    }

    $this->used[] = $id;

    return "<a id=\"{$id}\"><b>$content</b></a>";
    }
    }

    new Plugin_Glossitem();
    It adds the BBCode tag [glossitem].
    Usage:
    [glossitem]My Word[/glossitem]: definition of my word.
    It automatically add bold to "My Word" and creates an anchor based on the content (in this case my-word). I couldn't test it, tell me if anything is wrong!
    Regards,
    Piero
  • You solution sounds like the perfect fit :)

    I added the

    ?>

    at the end, is this correct? Anyway, in both cases I cant access any page on my blog. Everything stays white if the plugin is activated.
  • Hi, the ?> is optional.
    The homepage is white because there's some error but display errors is off.
    I'll check it...
    EDIT: I had missed a return $bbcode; . Now I've changed on the post above.
    Tested&working ;-)
  • How do I link to the anker? I created a static page called "glossar" and a anker called test.

    The link www.mywebsite.com/?u=/glossar/test

    leads to a none existing page.
  • You use HTML anchors :-)
    www.mywebsite.com/?u=/glossar#test
  • Thank you very much, one more thing I have to bug you with... is there a way to include special characters like ä ö ü and ß?

    I thin this is an essential plugin, this should be one of the flatpress standard plugins :)
  • Well, I've disabled this by default, in URLs, in the content they are ok.

    Since you are going to have an URL with them, I've thought it was better to use only ASCII characters, like entry titles with PrettyURLs/RewriteURLs (as matter of facts, the function to clean the item is the same).
    Including UTF-8 character should be legal in URL and in HTML tags, however I preferred not doing it.
    I'm Italian so I use non-ascii characters, like à, ù, è, but they are transformed to a, u and e automatically, so I think that yours should too (ä to a etc...).

    Finally, if you want to have these characters anyway, you have to change this:
    $sanitized = sanitize_title($content);
    to something like this (not checked, going by memory ;-) ):
    $sanitized = wp_specialchars($content, true); // Second parameter to escape quotes
    Bye, Piero
  • I tried it with a insted of ä but it doesn't work. I don't wont ä in the Url :)

    ä ö ü seems to be not transformed in a o u...
  • You can see the URL with your consolle. You analyze the glossary item and the id is your anchor
  • yes, but e.g.

    the content is ärger, the link would be
    www.mysite.de/?u=/glossar#arger

    but it doesn't work :) no error, it loads the whole glossar.
  • As I told you, please open your glossary with a browser like Firefox/Chrome/Iceweasel/Chromium.
    Then press F12, the consolle will open.
    There's a button with a magnifier or with a cursor.
    Click on it, then click on the glossary item, ärger, in this case.
    At this point look on the consolle: there should be something like <a id="arger"><b>ärger</b></a>: the correct id is what you should put on the anchor. If it is arger you should put #arger, otherwise, if it is rger you should put rger.
    Otherwise please link me your actual glossary, and I'll help you.
  • Sorry I didn't understand you at first :)

    ä isn't showing up. It is rger instead of arger. Could you look into the code that the plugin changes ä ö ü to a o u?

    That would be awesome :)
  • I've already told you ( http://www.flatpress.org/vanilla2/discussion/comment/11010#Comment_11010 ) :-) 
    $sanitized = wp_specialchars($content, true); // Second parameter to escape quotes
  • Thank you piero, I really don't want to annoy you but with this method, there are ä ö ü s in the URL.

    I would like to change the anker ärger to arger. so "ä ö ü" are changed to "a o u"

    Would this might help?
    http://stackoverflow.com/a/3371773
  • Well, it should be done automatically by sanitize_title...
    Did you try the solution above? It should allow all characters.
    Replace this:
    $sanitized = sanitize_title($content);
    with this:
    $sanitized = wp_specialchars($content, true); // Second parameter to escape quotes
    If I didn't mispell, it should work.
    Otherwise I could add a parameter to allow you to decide how to call the anchor.
  • I tried the solution above but then you have to look for captital letters like "Ärger" instead of "ärger" and I'm a little afriad of "Ärger" in the URL, I would prefer if "Ärger" gets changed to "arger".

    pierovdfn said:

    Well, it should be done automatically by sanitize_title...

    It delets the ä ü ö. Ärger changes to rger.

    For me it would be enough if Ärger changes to arger, but on the other side to define my own anchor would be great too :)
  • If you wnat lowercase, please change the line to this:
    $sanitized = strtolower(wp_specialchars($content, true));
    I could change the plugin to handle an optional anchor name ;-)

    EDIT: Please, check the plugin now.
    [glossitem=myname]My Word[/glossitem] should have myname as anchor.
    [glossitem]My Other Item[/glossitem] should be working too.
    Please check it and then let me know.
  • Great, I will check it today. thanks a lot piero!
  • Late Feedback :D Everything works great :) Just another question? Is it possible to make the anchors clickable? Right now, if i klick on an anker, nothing happens. I would like, if you click the linked anchor, that the site jumps to the anchor.

    Is this possible?
Start a New Discussion

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion