WordPress.org

Ready to get started?Download WordPress

Forums

Media Library Assistant
[resolved] Pagination (11 posts)

  1. Lrrr
    Member
    Posted 9 months ago #

    Hello, I had done pagination and working on rewriting to nice urls...
    but again nothing works now for me so I will bring solution as I will find.
    For now, solving the issue with unxexists pages. Because when you type
    ?mla_paginate_current=83738973973973
    it will show a page only without gallery content, instead of 404 ...
    I had google and found opposite problem here whats cloud be a nice guide for solving the issue.
    That problem is harmfull for SEO especially if your taxonomy template contains other content than MLA, which is being to be duplicated... (SEO? its one content one url = OK , one content several url's = BAD)

    http://wordpress.org/plugins/media-library-assistant/

  2. Lrrr
    Member
    Posted 9 months ago #

    So, challenge accepted. :D After day and one coffee night I spend every minute on forums picking up ideas and snippets, editing them and putting together Bringing this, even not ideal because:
    I can use nice urls with mla shortcode,
    but - old urls still works (they should be redirected to nice)
    Here is my results till now:

    First, if you interested, Im raising from thread rewrite-custom-taxonomy-slug so next code depends on that.

    So firstly in htaccess file i created a rule:
    RewriteRule ^fotografie/tag/([^/]+)/([^/]+)/?$ http://www.danielkral.cz/fotografie/tag/$1?mla_paginate_current=$2 [NC] - this rewrite query url with nice url, if you will use [R=301,QSA,L] instead shown, be sure that you'll be redirected - so in url you will see old query adress even if you type nice url.

    Second in taxonomy-attachment_tag.php file is code:

    echo apply_filters( 'thematic_open_id_content', '<div id="content">' . "\n\n" );
          $prev_page = do_shortcode( sprintf( '[mla_gallery %1$s="%2$s"  mla_output="previous_page" numberposts="7" mla_link_class="prev page-numbers" mla_link_text="<span class=\'meta-nav\'>◄</span> Předchozí"]', $wp_query->query_vars['taxonomy'], $wp_query->query_vars['term'] ) ) ;
          $next_page = do_shortcode( sprintf( '[mla_gallery %1$s="%2$s"  mla_output="next_page" numberposts="7" mla_link_class="next page-numbers" mla_link_text="Další <span class=\'meta-nav\'>►</span>"]', $wp_query->query_vars['taxonomy'], $wp_query->query_vars['term'] ) )	;
    			// displays the page title
    			thematic_page_title();
    
           $url =  get_bloginfo('url').parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);
           $ot = ''; if (parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY)) {$ot = '?';}
             $url_query =  $ot. parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY);
             $complt_url =$url . $url_query;
      // print( 'url: '.$complt_url.'<br> ' ) ;
      // print( 'query: '.$url_query. '<br>' ) ;
             $url_arr = explode("/",$url) ;
             $last = end($url_arr);
      // print( 'last: '.$last. '<br>' ) ;
      // print( 'term: '.$wp_query->query_vars['term']. '<br>' ) ;
      // print( 'while: '.$url_arr. '<br>' ) ; /**/
             $rep_url = $url;
    
    if ($last != $wp_query->query_vars['term']) {
    
         //vypisuje url az po term v url
       $rep_url = '';
       foreach ($url_arr as $value) {
        if ($value != $wp_query->query_vars['term']){
            $rep_url .= $value . '/';
        }else break;
       }
       $rep_url = $rep_url.$wp_query->query_vars['term'];   
    
        //print( 'url: '.$complt_url.'<br> ' ) ;
        //print( 'repurl: '.$rep_url.'<br> ' ) ;  
    
    }
        $rep_url_final_prev = preg_replace('/<a(.*)href="([^"]*)mla_paginate_current=(.*)"(.*)>/','<a$1href="'.$rep_url.'/$3"$4>',$prev_page);
        $rep_url_final_next = preg_replace('/<a(.*)href="([^"]*)mla_paginate_current=(.*)"(.*)>/','<a$1href="'.$rep_url.'/$3"$4>',$next_page);

    this code parse mla_gallery shortode and replace old query urls to nice urls.
    in place where you want use gallery shorcode , in template, put this code:

    <?php echo $rep_url_final_prev;
                echo $rep_url_final_next; ?>

    That should works. Finaly I want to know you that this solution is not as good as is difficult. Your old query links probably will works still and dont know why, the wordpress redirecting rules not giving 404 error page on most things after query string even after nice url.
    (put "?mla_paginate_current=4" for example after nice url, if used page number nothing happened but url not redirect, if just after term it works - both states are not ideal)
    If anynone could contribute I will be glad.

    Partially working http://www.danielkral.cz/fotografie/tag/atelier/3 (maybe little different yet because in development still)

  3. David Lingren
    Member
    Plugin Author

    Posted 9 months ago #

    Thank you for raising this issue and sharing the work you have done to address it. I want to make sure I understand what you are trying to do. It looks like you have a page that displays an [mla_gallery] with the items that match a term in the attachment_tag taxonomy, and you have used the pagination parameters to divide the gallery into pages of seven items each. Your approach includes some ideas raised in an earlier support topic:

    Pagination Revisited

    The mla_paginate_current parameter was introduced to avoid mixing the [mla_gallery] pagination with the standard WordPress logic that paginates archives of posts and pages. It is intended to hold the post ID of the "current" item in the gallery, and is normally managed by the MLA plugin. Entering a value such as "83738973973973" has no meaning and would not happen in normal use.

    The issue you are working on is to re-write the URLs to look more like the standard WordPress URLs. For example, http://www.danielkral.cz/fotografie/tag/story?mla_paginate_current=$2 would become http://www.danielkral.cz/fotografie/tag/story/2; is that right?

    Then, when the "nice" link is entered, the rewrite rule you created would change the "/2" portion of the URL back to the "?mla_paginate_current=2".

    If I have understood all that correctly it looks like you are close to a solution. However, I am confused by the "/tag/" part of your URLs and the comments you made in your other topic (rewrite custom taxonomy slug?). How do you get from the "/tag/" in the URL to the taxonomy-attachment_tag.php file that handles the query? Why not use \attachment_tag\ in your URLs?

    I hope I am understanding you well enough to be helpful. Thanks again for all your efforts.

  4. Lrrr
    Member
    Posted 9 months ago #

    David, I carefully read your post. I have used your advices from "Pagination Revisited" article and my code is based on. But Im using it divergently.
    My question about unexisting page "893798 etc." is not much important but I supposed that this should be handled by "get_template_part( 'loop-error' );" so it isnt.

    Further,

    For example, http://www.danielkral.cz/fotografie/tag/story?mla_paginate_current=$2 would become http://www.danielkral.cz/fotografie/tag/story/2; is that right?

    You are fully right! But im not able to made it bullet-proof for opposite working. Both urls from these two working now, it should not be. (should works like: http://www.danielkral.cz/fotografie/tag/story?mla_paginate_current=$2 redirect to NICE URL. => only nice url active, visitor see nice only) This is not a question for you concerning your plugin. I "parsed" your code as you can see and changed urls to nice because otherwise it wasnt working correctly.

    Finally dont be confused about my urls, its easy. My web is structural (should be), it have two basic sections: Blog and Photography (infact they are four, about me and contact yet, but these are single - want them in the row). Because mla plugin (attachment_tag taxonomy) im using in photography section, links in that section I want have based here, so in .cz/fotografie/ . Even the visitor browsing in gallery, he should know, in which category (or tag, term) is paginated. Or he can send a link and who clicked on it knowing for what ;) If I used mla plugin default links it was targeting to base .cz/ . So firstly I created page as subpage photography and insert mla shortcode there. Generally you can say, that I switched /attachment_tag/ for /fotografie/tag/ because there is a structure easy readable from, and the second, tag slug is more simple than attachment_tag slug. (I know that tag slug uses WP in but I can rename it if I have to, Im using it as universal not as taxonomy exact - for original tag slug Im using téma which mean topic in english. )

    I think we wrote about that topic already something.

    In future , if I will need use attachment tag even for blog section, I will have remake the code, I now, but it could be a THEME or IDEA for you : show attachment_tag accordingly to which category or parent article is linked. Like, be more structural. Thank you for your readings and have a nice day today ;)

  5. Lrrr
    Member
    Posted 9 months ago #

    Update: its true as I wrote, but for better understanding, BLOG section I have as such a cross-road, something (have to be always) first, therefore no slug for it. Just root. :)

  6. Lrrr
    Member
    Posted 9 months ago #

    I did several upgrades to code so now you dont need to create page named TAG in parent FOTOGRAFIE (in my case).

    Even now its working ONLY nice URLs! wooow, im proud to myself and I will bring the code after if...

    ...if I (hope someone helps, I cant get it work for whole day) solve this annoying issue http://wordpress.org/support/topic/mod_rewrite-htaccess-works-but-ie?replies=1#post-4727521

  7. Lrrr
    Member
    Posted 9 months ago #

    Hi David and everyone, I get to work! Nice url pagination with MLA! Finally cannot say what make it work exactly and what causees the issue with IE(above), because I was trying almost everything and suddenly get it work. So I supposing it was rewrite parameter after rewrite rule together with rewrite rule itself(even some other??), but now I will put in general way the main things you should do to use that. I want highlight that this way maybe not the best, but I cant do it better, and it works. READ FIRST - THEN YOU ADD AND BACKUP BEFORE CHANGE!

    1) put in your .htaccess these lines of code before wordpress code (this and the next code provides you ability to change attachment_tag slug also, so if you want it remain all "fotografie/tag" substitute with "attachment_tag" in this and subsequent code!):

    RewriteCond %{QUERY_STRING} ^mla_paginate_current=([0-9^/]+) [NC]
    RewriteRule ^(.*)$ http://www.yourwordpresssite.com/?mla_redirect=$1 [R=301,QSA,NC,L]           
    
    RewriteRule ^attachment_tag/(.*)/?$ fotografie/tag/$1 [R=301,QSA,L]
    RewriteRule ^fotografie/tag/([^/]+)/1/?$ fotografie/tag/$1 [R=301,QSA,L] #zalezi na poradi!
    RewriteRule ^fotografie/tag/([^/]+)/0/?$ fotografie/tag/$1/$2?mla_redirect=error [NC]  
    
    RewriteRule ^fotografie/tag/([^/]+)/([0-9^/])/?$ index.php?attachment_tag=$1&mla_paginate_current=$2 [NC]

    2) Put this code in your function.php of your theme or childtheme (This code is to add redirect to WP. I dont know why, but its not works only with .htaccess or only woth this code. It works only together.):

    function mla_rewrite( $wp_rewrite ) {
        $mla_rules = array(
            'fotografie/tag/([^/]+)/?([0-9])?/?' => 'index.php?attachment_tag=$matches[1]&mla_paginate_current=$matches[2]'
    
        );
        $wp_rewrite->rules = $mla_rules + $wp_rewrite->rules;
        return $wp_rewrite->rules;
    }
    add_filter( 'generate_rewrite_rules', 'mla_rewrite' );

    3) I made function for redirecting old query urls to new nice. It handles variables from .htacces. Redirecting this is good for seo and when you do not will want to parse mla gallery code in taxonomy template. So also this code belongs to function.php:

    function handle_mla_redirect() {
       $url_query_var = explode('=',parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY));
       $url =  parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);
       $url_host =  get_bloginfo('url').parse_url($_SERVER['REQUEST_URI'],PHP_URL_HOST);
       $lom = ''; if ($url_query_var[2]!='') {$lom = '/';}
       $rep_url_fin = $url_host.'/'.$_GET["mla_redirect"].$lom.$url_query_var[2];
      // print( '<br>presmeruj ted na: '.$rep_url_fin. '<br>' );
    
        if(  isset($_GET["mla_redirect"]) && ($_GET["mla_redirect"]=='error')  ){  dk_return_404();  }
    
        if ( isset($_GET["mla_redirect"]) && (parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY)!='') )  {
          // print( '<br>presmeruj ted na: '.$rep_url_fin. '<br>' );
          // print(parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY). '<br>');
    
           wp_redirect($rep_url_fin, 301 ); exit;  
    
       }
    }
    add_action('template_redirect', 'handle_mla_redirect'); /**/

    4) if you want to mla gallery shortcode in your taxonomy-template.php generate the nice urls instead the queries you can use before mentioned code which is dirty parsing of mla_shortcode and repasing urls generated for pagination. It here, so go above .

    how it works together you can now test(if not currently, come back later): old link to new - http://www.danielkral.cz/fotografie/tag/mobilem?mla_paginate_current=2
    and new one (try to browse) http://www.danielkral.cz/fotografie/tag/mobilem/2

    I must bring also resources which I found about this topic on web, it could be helpfull for anyone who want improve this: - link 1 - this works exactly opposite in this case, but gave a clue

    helpfull but still do not understand why not works alone without .htaccess - codex WP link

  8. David Lingren
    Member
    Plugin Author

    Posted 9 months ago #

    Congratulations on working your way through to a solution and thank you for sharing your work here. I hope it will be useful for anyone else using rewrite rules to transform URLS with query parameters to pure/pretty URLs.

    Good luck with the rest of your site development. Let me know if there's anything else I or MLA can do to help.

  9. Lrrr
    Member
    Posted 9 months ago #

    Thank you for your words! Congrats from you, is very good to listen for me :) Did you recieve my info through contact form on your web before week or two ago? Its concerning 1.50 update.

  10. David Lingren
    Member
    Plugin Author

    Posted 9 months ago #

    You are most welcome. Yes, I did receive your information and I have sent two replies to the address you gave me since then. I will re-send them shortly. If you do not receive them, go back to the contact form and try again, perhaps with a different return e-mail address.

  11. David Lingren
    Member
    Plugin Author

    Posted 9 months ago #

    Daniel,

    I just received your latest message. I have sent you five e-mail replies from two different e-mail providers; the last attempt was sent on October 14 at 14:55 Pacific Daylight Time. I do not know why these messages are failing to reach you; there are no errors reported back to my accounts. Do you have any e-mail accounts at a provider other than email.cz?

    Rest assured, I have read all of your messages and I have found and fixed (in the next version) the issue you reported regarding false matches in the "where-used" columns.

    I am sorry that the e-mail communication hasn't worked for us.

Reply

You must log in to post.

About this Plugin

About this Topic