Jquery Mobile with 2 set of page

2019-02-28 12:30发布

问题:

I have a wordpress site, that need to show pages using swipe, I choose to use Jquery Mobile, and I get it working fine. Now, we have 2 languages on site, using wpml plugin. And my Swipe Code works well, except when we use Change language button swipe fails.

Details on issue.

We have only 3 Text Only page in our website, in 2 language. And in Footer we have link to change language. Also client hate to have Ajax page loading, so what I did is I create three Div with data-role=page and put data-next, data-prev as #div-$postid. So the navigation works absolute fine. I put footer outside from data-role=page.

Now, when I click change button in footer, it load the english page [I saw it using Fiddler] and then take first data-role=page from server and replace /slide its content. However since it only pick the first data role, all other english page doesn't get in HTML [it just update DOM and doesn't navigate to english version]. so swipe fails as other english pages are not in dom.

Also, footer is not changing, so what I want is: can we simple force a Link to navigate instead of going swipe way? Jquery Mobile is enforcing swipe on all A tags, I do not want swipe to works anything outside data-role=page.

Hope I make sense.

Edit here is code: [not sure if this code will help at all]

<?php 
    get_header(); 
global $post;   
$args = array('post_type' => 'mobile_slide','showposts' => '-1', "order" => "DESC");

$the_query = new WP_Query($args);            
if($the_query->have_posts()){
    while($the_query->have_posts()) { $the_query->the_post();
    $prev =get_previous_post();
    $next =get_next_post();
    if($prev) {
        $prev = "#page-" . $prev->ID; //get_permalink($prev->ID);
    } else {
        $prev='';
    }
    if($next) {
        $next = "#page-".$next->ID; //get_permalink($next->ID);
    } else {
        $next='';
    }

    if (has_post_thumbnail( $post->ID ) ) {     
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'slider_image' ); ?>
        <div id="page-<?php echo $post->ID; ?>" data-dom-cache="true"  data-transition="slide"  class="page" data-role="page" data-prev="<?php echo $prev; ?>" data-next="<?php echo $next; ?>" style="background-image:url('<?php echo $image[0]; ?>'); background-position:center center; background-color:#000; background-repeat:no-repeat; ">
        <?php } else { ?>
        <div id="page-<?php echo $post->ID; ?>" data-dom-cache="true"  data-transition="slide" class="page" data-role="page" data-prev="<?php echo $prev; ?>" data-next="<?php echo $next; ?>"> 
        <?php } ?>
        <div class="post_box">
            <h2><blockquote><?php the_title(); ?></blockquote></h2>
            <div class="post_entry">
               <?php the_content(); ?>
            </div>
        </div><!-- post_box -->
        </div>

   <?php   } 
   } ?>
   <?php get_footer(); ?>

This is all I have, except that get_footer use Ul li based list where on LI change based on language variable, to show different images for either language.

回答1:

To stop Ajax from loading pages/links, add to link anchor data-rel="external" or data-ajax="false". This will load page normally without any transition.

Reference: jQuery Mobile - Links



回答2:

For those who have similar problem, I fix it by using following:

1) I add a "noswipe" class to A Tag so I can refer it in Jquery

2) I add following code

$(function(){
  $(".noswipe").click(function(){
     window.location.href= $(this).attr("href");
      return false;
   });
 }); 

The above code simply enforce to skip the Mobile's parsing and calling and works for my case.