Next and Previous buttons on Detail Page

This topic contains 10 replies, has 2 voices, and was last updated by  Kiran 7 years, 2 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #366000

    rigots
    Lifetime Member
    Post count: 275

    Hi,
    I am using Starter Directory Theme and Supreme child theme.

    Selected “Enable location filter on related post” under ‘Geodirecory->Design->Detail’ tab on the ‘Related Post Settings’ section.

    From this selection I see a “Next” and “Previous” button at the bottom of my detail page. I like that option, but when I click on next, it seems to ramdomly select any listing as the next listing.
    I would like to stay on the same listing, for example if I am viewing a photography listing and I click on next I wan to see another photography listing, not some other category listing. Is there a way to do that?

    Under the “Related Post Settings” I have set “Relate to” to “Caterories”.
    The “Sort by” option is set to “Latest”. I wish it has the option to sort by “Category” is there a way to do that?

    So, when I click on next at the bottom of the page I would like to go to the next listing but in the category, is there a way to do that?

    Thank you.

    #366034

    rigots
    Lifetime Member
    Post count: 275

    Hi I see I had some spelling errors in my previous post.
    I meant to say that when I click on the next button at the bottom of the detail page I would like to display another listing of the same category, not just some random listing.

    Thanks,

    #366074

    Kiran
    Moderator
    Post count: 7069

    Hi Rigots,

    > Under the “Related Post Settings” I have set “Relate to” to “Categories”.
    The “Sort by” option is set to “Latest”. I wish it has the option to sort by “Category” is there a way to do that?
    < No, currently there is no such option to sort by categories for Related Listings.

    > So, when I click on next at the bottom of the page I would like to go to the next listing but in the category, is there a way to do that?
    < Use following code snippet to show next/previous listing within current category only.

    
    
    
    function gd_previous_next_post_with_same_category( $where, $in_same_term, $excluded_terms, $taxonomy, $post ) {
        global $wpdb, $plugin_prefix;
    
        if ( !empty($post->post_type) && !empty( $post->default_category ) && in_array( $post->post_type, geodir_get_posttypes() ) ) {
            $conditions = " AND default_category = %d";
            $values = array( (int)$post->default_category );
            
            $where .= $wpdb->prepare( $conditions, $values );
        }
        
        return $where;
    }
    add_filter( 'get_previous_post_where', 'gd_previous_next_post_with_same_category', 11, 5 );
    add_filter( 'get_next_post_where', 'gd_previous_next_post_with_same_category', 11, 5 );
    

    Thanks,
    Kiran

    #366269

    rigots
    Lifetime Member
    Post count: 275

    Hi Kiran,
    Thank you for the info. This almost worked.

    Each time I search a category and then go into one of its listings then I only see a “Previous” button at the button of the details page. If I click on the previous button then it goes to previous listing in the same category and it gives me the option to go select only “Next” and I can go to the next listing too and then I only have the option to select previous as if I had only two listings to toggle in, but there are 4 or more listings on the categories I am using to test this.

    Any idea what might be happening?

    #366514

    Kiran
    Moderator
    Post count: 7069

    Hi,

    Previous & Next listing also filters the current location.
    For ex:
    Suppose current listing has location “san-jose” & default category “catering” then it shows Previous & Next listings if listings has location “san-jose” & default category “catering”.

    If you reason except this then let me know steps with urls.

    Thanks,
    Kiran

    #367303

    rigots
    Lifetime Member
    Post count: 275
    This reply has been marked as private.
    #367384

    Kiran
    Moderator
    Post count: 7069
    This reply has been marked as private.
    #367399

    rigots
    Lifetime Member
    Post count: 275
    This reply has been marked as private.
    #367400

    Kiran
    Moderator
    Post count: 7069
    This reply has been marked as private.
    #367598

    rigots
    Lifetime Member
    Post count: 275

    Hi Kiran,
    Do you have any sample custom code on how to use next/previous skipping the location filter?

    When I do a search and land on the search results and then I click on one listing details I would like the next and the previous listing to be in the order of the search results.

    Is these doable?

    #367639

    Kiran
    Moderator
    Post count: 7069

    Hi There,

    You can use following code snippet to skip location filter from previous/next links.

    
    
    function gd_plugins_loaded() {
        remove_filter( 'get_previous_post_where', 'geodir_previous_next_post_where', 10, 5 );
        remove_filter( 'get_next_post_where', 'geodir_previous_next_post_where', 10, 5 );
    }
    add_action( 'plugins_loaded', 'gd_plugins_loaded' );
    

    To filter next/previous listing links with searched results, it required more code customization so you have to hire developer to do that.

    Thanks,
    Kiran

Viewing 11 posts - 1 through 11 (of 11 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket