Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Feb 2017
    Location
    Tokyo, Japan
    Posts
    272
    Plugin Contributions
    0

    Default How to define anchors (fragment identifiers) in define pages?

    Hello all,
    I searched for this online and on the forums to no avail. I'd like to use anchors in my define pages (main page, shipping, conditions, contact us, etc.). I create sub-sections and refer to them in a table of contents list, as well as having a return to top link in each sub-section.
    I am having trouble with the anchor / fragment identifier. I am open to alternative suggestions too of course.

    Ordinarily, an identifier such <h2 id=top> would be referenced like href="#top", and the browser would not need to reload the page. However, since the page URL is actually a query of the form index.php?page=conditions I find I need to define the fragment also as id="index.php?page=conditions#top". I presume this reloads the page.
    Furthermore, if I have multiple languages (selected via language icons on the page, such that the URL then includes "&language=en" for example" then I need to include that also into the anchor definition, corresponding to the the language version of the define page.

    Is there a different approach I can take for anchors in the define page editor, or to achieve what I would like, namely a quick way for the user to get back to the top of the page (or another section of same page) with a mouse click?

    Note: My site is currently available locally only pending regulatory approval, if access is required I can open up preferably only to specific IP addresses.
    Last edited by gernot; 18 Jun 2019 at 06:23 AM.
    Zen Cart 1.5.6c modified for Japanese language support. Upgraded incrementally from initial 1.5.5d. Currently planning direct upgrade to 2.0.0 with available Japanese language pack and far fewer required plugins.

  2. #2
    Join Date
    Sep 2008
    Location
    DownUnder, overlooking South Pole.
    Posts
    976
    Plugin Contributions
    6

    Default Re: How to define anchors (fragment identifiers) in define pages?

    It goes something like this (would say more but running out of time with building about to close)

    1. In your \includes\languages\english\html_includes\YourTemplate\define_yourpage.php

    Code:
    <p class="forward"><a href="index.php?main_page=yourpage#top"><?php echo zen_image_button(BUTTON_IMAGE_BACKTOTOP, BUTTON_BACKTOTOP_ALT); ?></a></p>
    However zen_image_button code may depend upon what sort of buttons you use.

    2. Before the last </div> in your page template file

    Code:
      <div class="buttonRow forward"><a href="index.php?main_page=yourpage#top"><?php echo zen_image_button(BUTTON_IMAGE_BACKTOTOP, BUTTON_BACKTOTOP_ALT); ?></a></div>
    Hope this helps.

  3. #3
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: How to define anchors (fragment identifiers) in define pages?

    As a "proof" to another some time ago, I had modified the default define_page_2 text to include a clickable link to return to the "top" of the page. There is no page load that occurs at least not quite like one would think as in a retrieval and download time period, just a movement within the given page.

    Anyways, on index.php?main_page=page_2, I added a single link to go to an existing id tag that was located at/near the top of that page.

    My added link was:
    Code:
    <a href="<?php echo zen_href_link($_GET['main_page'], zen_get_all_get_params(array('main_page')), $request_type, false); ?>#page">click</a>
    This way, I don't have to "know" what page I'm on, the code is flexible to be put on whatever page. Basically if able to get to the page that is displayed, then able to get to the tag that is also on that page. In this case the tag to be reached was id="page" which happened to be on the page but not in the define_page_2 text.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #4
    Join Date
    Feb 2017
    Location
    Tokyo, Japan
    Posts
    272
    Plugin Contributions
    0

    Default Re: How to define anchors (fragment identifiers) in define pages?

    Many thanks for the replies!
    dw08gm: great idea, so this gives a "built-in" button on the page, handled by the code rather than being done in the define page editor. I also want links in the content, but this certainly works for me as a starting point.
    mc12345678: Very interesting, I did not realize one can put PHP code in the define page editor contents. Definitely missing the big picture here as far as the admin power goes!

    I will give both these a try tonight and report back.

    PS: I made an error in my initial post, the href only needed the "?...#..." part, not "index.php?...#..."
    Zen Cart 1.5.6c modified for Japanese language support. Upgraded incrementally from initial 1.5.5d. Currently planning direct upgrade to 2.0.0 with available Japanese language pack and far fewer required plugins.

  5. #5
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: How to define anchors (fragment identifiers) in define pages?

    Note that, if you have an html editor such as ckeditor installed and active, you will have to go into source editor mode for the php code to "take". Otherwise, visitors will see the text (php) as typed.

    As an additional note, when building internal links, you want to use zen_href_link() type calls as much as possible so that your code is portable to any domain, sub-folder, etc... So long as the store is functioning in whatever environment, the links will be consistent and in the above case, the code can be copied to multiple locations with little effort updating just the id tag for that page.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Feb 2017
    Location
    Tokyo, Japan
    Posts
    272
    Plugin Contributions
    0

    Default Re: How to define anchors (fragment identifiers) in define pages?

    mc12345678, worked a treat, exactly what it seems I needed! Thank you very much.
    I had no idea the define pages was so powerful (extremely mistakenly assumed it was severely sanitized HTML only).
    I do have CKEditor installed since 1.5.6b, as a convenience for my partner when she corrects the Japanese texts, but I do my normal editing in the text editor (especially some some contents are initially copied from an existing Wordpress site).
    Thanks for pointing out how to get source mode there!
    I'll have to study at bit more on how to use the zen_href_link() function, it is going to become extremely used on my pages!
    Zen Cart 1.5.6c modified for Japanese language support. Upgraded incrementally from initial 1.5.5d. Currently planning direct upgrade to 2.0.0 with available Japanese language pack and far fewer required plugins.

  7. #7
    Join Date
    Sep 2008
    Location
    DownUnder, overlooking South Pole.
    Posts
    976
    Plugin Contributions
    6

    Default Re: How to define anchors (fragment identifiers) in define pages?

    Thanks MC# I will certainly consider your code.

    For my (old) code to work, you may need to add item 3:

    1. In your \includes\languages\english\html_includes\YourTemplate\define_YourPage.php

    Code:
    <p class="forward"><a href="index.php?main_page=yourpage#top"><?php echo zen_image_button(BUTTON_IMAGE_BACKTOTOP, BUTTON_BACKTOTOP_ALT); ?></a></p>
    However if you prefer to use text instead of a button, you could use this:

    Code:
    <p class="forward"><a href="index.php?main_page=yourpage#top"><b>Back to Top</b></a></p>

    2. In your \includes\templates\YourTemplate\templates\tpl_YourPage_default.php, before the last </div>

    Code:
      <div class="buttonRow forward"><a href="index.php?main_page=yourpage#top"><?php echo zen_image_button(BUTTON_IMAGE_BACKTOTOP, BUTTON_BACKTOTOP_ALT); ?></a></div>

    3. In your \includes\templates\YourTemplate\common\tpl_header.php, add the following immediately after <div id="headerWrapper"> (or whatever div contains your header file)

    Code:
    <!-- bof Back to top - see tpl_YourPage_default.php -->
        <a name="top"></a>
    <!-- eof Back to top -->
    Cheers


    ps there is also a Back to Top plugin (from 2012) and support thread available here:

    https://www.zen-cart.com/downloads.php?do=file&id=1574

    https://www.zen-cart.com/showthread....Support-Thread

  8. #8
    Join Date
    Feb 2017
    Location
    Tokyo, Japan
    Posts
    272
    Plugin Contributions
    0

    Default Re: How to define anchors (fragment identifiers) in define pages?

    Many thanks for the additional information. I haven't edited the template files yet, although I did check them to see which "id"s were available to reference in some pages.
    After some reading of the code, I could figure out how to link to other pages as well, with or without referencing a fragment in that page. Really great!
    Code:
    <a href="<?php echo zen_href_link($page='contact_us', zen_get_all_get_params(array('main_page')), $request_type, false); ?>">Contact</a>
    Zen Cart 1.5.6c modified for Japanese language support. Upgraded incrementally from initial 1.5.5d. Currently planning direct upgrade to 2.0.0 with available Japanese language pack and far fewer required plugins.

  9. #9
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: How to define anchors (fragment identifiers) in define pages?

    Quote Originally Posted by gernot View Post
    Many thanks for the additional information. I haven't edited the template files yet, although I did check them to see which "id"s were available to reference in some pages.
    After some reading of the code, I could figure out how to link to other pages as well, with or without referencing a fragment in that page. Really great!
    Code:
    <a href="<?php echo zen_href_link($page='contact_us', zen_get_all_get_params(array('main_page')), $request_type, false); ?>">Contact</a>
    Unless there is a need to assign/create the variable $page in the content of the page where that code is located, then it could be removed to look like this:
    Code:
    <a href="<?php echo zen_href_link('contact_us', zen_get_all_get_params(array('main_page')), $request_type, false); ?>">Contact</a>
    That said though, there is a constant that already defines the main_page value for you, again allowing the code to remain "generic". FILENAME_CONTACT_US

    So this could be written:
    Code:
    <a href="<?php echo zen_href_link(FILENAME_CONTACT_US, zen_get_all_get_params(array('main_page')), $request_type, false); ?>">Contact</a>
    Which should look relatively familiar if you review template files where the contact us link is offered.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  10. #10
    Join Date
    Feb 2017
    Location
    Tokyo, Japan
    Posts
    272
    Plugin Contributions
    0

    Default Re: How to define anchors (fragment identifiers) in define pages?

    Thank you for that advice, I changed all the "$page->..." to FILENAME... as appropriate.
    For define_<pagename>.php the constants for a given <pagename> seem to be:
    1. contact_us: FILENAME_CONTACT_US
    2. privacy: FILENAME_PRIVACY
    3. conditions: FILENAME_CONDITIONS
    4. shippinginfo: FILENAME_SHIPPING (not SHIPPINGINFO)

    Between mc12345678 and dw08gm I am getting the feel for how to manage the backend and GUI sides together, after having started assuming they were separated strictly. Nice!!

    Aside:
    1. Not sure where the '<pagename>' variables come from (which I could use instead of FILENAME...), are these defined globally?
    2. define pages page_{2,3,4} exist also, but I cannot find where their links are in Zen Cart on the main page (I will have a look in the code at home tonight). So I disabled them for now.
    Zen Cart 1.5.6c modified for Japanese language support. Upgraded incrementally from initial 1.5.5d. Currently planning direct upgrade to 2.0.0 with available Japanese language pack and far fewer required plugins.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Using HTML named anchors in define pages
    By lat9 in forum General Questions
    Replies: 3
    Last Post: 4 Jun 2012, 02:02 AM
  2. Define Pages - How to define brand new page
    By hutch32804 in forum Customization from the Admin
    Replies: 4
    Last Post: 31 Oct 2009, 01:39 PM
  3. index_default & define pages(4+ define pages on frontpage?)
    By mrmarcus66 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 13 May 2006, 07:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR