• I have now these 2 buttons in the single post page:

    <?php
    
    echo '<form><input type="button" value="< Torna alla lista" onClick="javascript:history.go(-1)"></form>','<form><a href="#my_map_123"><input type="button" class="listino" value="Listino" ></a></form>' ;

    After I put a second button with an anchor to the same page, the first button doesnt work well, If I use the second button, than I have to click 2 times on the first button to go back to the previous page. So, what I need is a code, in java or php, so that when I click to “go to the previois page” I’ll land in the parent category page

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Moderator bcworkz

    (@bcworkz)

    That’s because you’re just going back one step in browser history. The first alla lista click goes back to the same page because it’s only undoing the jump down to the map. You’d have to click again to go farther back.

    I’m not sure browser history is a good solution here. If someone lands on this page from Google search, going back in history would return them to their Google search results page, not the alla lista promised. Why wouldn’t you link back to the regional listing page using its actual URL instead of relying on JavaScript and browser history?

    FYI, “Java” and “JavaScript” are two entirely different, unrelated programming languages. Actual Java code here wouldn’t be very useful since browsers do not natively run Java. I knew what you meant though ??

    Thread Starter sacconi

    (@sacconi)

    Hi, I know I just jump back (-1). Any idea to link by php the parent category?

    Moderator bcworkz

    (@bcworkz)

    I believe you want to link to the category archive page for the category term assigned to the current post. (Marina di Massa) That’s not really a “parent category” because “parent” has a specific meaning in relation to hierarchical taxonomies. I’m sure the difference seems pedantic, but using proper terminology is helpful when communicating with others. I’m pretty sure I get your meaning though, even if it’s not quite accurate.

    You can get the terms assigned to the current post with wp_get_post_terms(). Things are easier if there is only one term assigned to any post in any given taxonomy. Otherwise code will need to know which of the several terms to use. The function always returns an array, even with only one term assigned. With one term, it’ll be the term object at index 0. You could thus generate the archive page’s URL from single post template code with something like:
    $url = get_term_link( wp_get_post_terms( get_the_ID(), 'category')[0], 'category');
    I’m assuming your categories are the default “category” taxonomy and not some alternative taxonomy like “apartment-category” or something. What ever it is, use the correct taxonomy slug in the above code.

    Thread Starter sacconi

    (@sacconi)

    I have to put this code in an html element like

    echo '<form><a href="$url = get_term_link( wp_get_post_terms( get_the_ID(), 'category')[0], 'category')"><input type="button" class="listino" value="Listino" ></a></form>' ;

    ?

    Yes, going back from single post to archive page containing it, you saw right, i.e: from here: https://test.sacconicase.com/lignano-sabbiadoro-appartamento-in-posizione-centrale-per-8-persone/ to here: https://test.sacconicase.com/case-vacanza/italia/friuli-venezia-giulia/lignano-sabbiadoro-appartamenti-vacanze/

    I know language is important but I’m not a developer, I’m a sorcerer’s apprentice

    Moderator bcworkz

    (@bcworkz)

    More like this:

    $url = get_term_link( wp_get_post_terms( get_the_ID(), 'category')[0], 'category');
    echo '<form><a href="', $url, '"><input type="button" class="listino" value="Listino" ></a></form>';

    I’m a sorcerer’s apprentice

    ?? Good description! I got that impression. I was hoping to help you become a better technical communicator. If you’d prefer to not be informed of improper terminology, I can stop offering corrections. As long I initially understand your meaning.

    Thread Starter sacconi

    (@sacconi)

    it works but there are a couple of things to fix. First when I go back to category I jump all the time at the top of the category, instead I should jump back to the pic I clicked on. Second, for just an instant I see a square right near the button when I click on it https://test.sacconicase.com/marina-massa-alloggio-giardino/

    You can make observations also about the language, maybe I’m going to learn something. About last time I was aware category is not parent to post from a technical point of view, I made reference to the breadcrumbs order, just to make you understand the sense of what I had in mind

    Moderator bcworkz

    (@bcworkz)

    I’m not seeing any square for an instance, so I cannot speculate on what that might be.

    To return roughly to the correct spot on the archive listing, when you construct the URL, you need to get the current post’s ID and use it so the alla lista URL looks something like:
    https://test.sacconicase.com/case-vacanza/italia/toscana/marina-di-massa-appartamenti-vacanze/#post-4528
    If the current post ID is 4528. This will not be the exact scroll position as before. The selected post will appear at the top of the viewport, even if it was near the bottom when you first clicked on it. Because the URL is not taken from history it’s not possible to achieve exactly the same scroll position.

    Thread Starter sacconi

    (@sacconi)

    Ok, so maybe the best solution is delete the button and use the default”go back” button on browser. Or maybe showing the old “go back button” in java I used, only if it’s possible to make it appear when I come on the post page from archieve page. It’s possible coding it?

    Thread Starter sacconi

    (@sacconi)

    AirBnb lets visitors go back at the same scroll position, is it possible their button simulate the browser default “go back” button?

    • This reply was modified 1 year, 4 months ago by sacconi.
    Thread Starter sacconi

    (@sacconi)

    Any possibility at least to go back to the correct page number since I have a pagination function and the archive is split on more pages?

    Moderator bcworkz

    (@bcworkz)

    is it possible their button simulate the browser default “go back” button?

    Yes, with JavaScript like you had before. But “go back” is not necessarily how someone got to the single page.

    Alternately, get the “referer” URL out of the $_SERVER array and use that to populate the link’s href attribute. Same issue, the referrer may not be for one of the archive pages.

    Maybe you could do a hybrid solution. If the referrer URL goes to the archive page, use it. It’ll have the correct page number in the URL. If the referrer is not an archive page, link to the first archive page. It then doesn’t matter as much if the current single post is on the first page or not since the user didn’t come from the archive listing.

    Thread Starter sacconi

    (@sacconi)

    Imagine a day I’ll have a search box with many filters, when I list the search results and then I enter an apartment details page, I could need a “back to search results” button. Finally a simple java “back” button is the best. If you get this page from the search engines you dont need going back to any list or search results, so you dont push the button. You’ll quickly understand what the button is for. What is a mistery for me is why AirBnb let open one different page for each apartment from a search results listing. you have soon to click and close each new page or you’ll have the browser unusable

    Moderator bcworkz

    (@bcworkz)

    My spouse is the AirBnB expert. I’ve only seen the site when we review prospective properties together. I’ve never really directly used it myself ?? I think I understand what you describe though. Perhaps they do that because of the difficulty in returning back to the right place in search results.

    I’ve encountered other sites which presume to know how I like to navigate a website. It’s aggravating when I’m forced to navigate in a way contrary to my wishes. On my sites I choose to not presume how one navigates. I do not provide any aids other than maybe a breadcrumb trail. No back buttons, no forced open in new tab. People know how to navigate a site the way they want to. IMO there’s no reason to try to help them because we don’t know how they like to navigate.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘button leading to the parent cathegory page’ is closed to new replies.