WordPress.org

Ready to get started?Download WordPress

Forums

mobble
combining conditionals (18 posts)

  1. earthjibber
    Member
    Posted 9 months ago #

    Hi

    Is it possible to combine mobble conditionals with wp conditionals? For example, I want to do something like this:

    <?php if (is_page_template('template-name.php') || (!is_mobile() || (!is_tablet())) { ?>
     code here
    <?php } ?>

    I tried using it and it didn't work for me, is there a way to combine them?

    thanks

    http://wordpress.org/extend/plugins/mobble/

  2. inTOWN
    Member
    Posted 6 months ago #

    Hi there, I have the same question...
    I used

    if (is_mobile()) { ... }
    else {... }

    But I am getting double content

  3. scottsweb
    Member
    Plugin Author

    Posted 6 months ago #

    Hi
    @inTown Can you post your full code here. I think these two problems might be unrelated.

    In answer to @earthjibber - I think it is to do with the way your grouping your conditionals. Try one on each line and see how that goes.

  4. inTOWN
    Member
    Posted 6 months ago #

    I had fixed the desktop problem, but still had the problem with iPad > i think is_mobile is also calling the iPad?

    <?php if (is_mobile()) {
                            $attr = array(
                            'title'	=> 'meer info over '.get_the_title(),
                            'width' => 390,
                            'height' => 'auto'
                        ); ?>
                    	<a href="<?php the_permalink(); ?>" title="Meer info over <?php the_title();?>"><?php the_post_thumbnail('medium', $attr); ?> <div class="clearer"></div></a>
                    <?php } ?>
    
                    <?php if (is_tablet()) {
                            $attr = array(
                            'title'	=> 'meer info over '.get_the_title(),
                            'width' => 187,
                            'height' => 256
                        ); ?>
                        <a href="<?php the_permalink(); ?>" title="Meer info over <?php the_title();?>"><?php the_post_thumbnail('small', $attr); ?> <div class="clearer"></div></a>
                    <?php } if ( !is_mobile() ) {
                            $attr = array(
                            'title'	=> 'meer info over '.get_the_title(),
                            'width' => 187,
                            'height' => 256
                        	); ?>
                        <a href="<?php the_permalink(); ?>" title="Meer info over <?php the_title();?>"><?php the_post_thumbnail('medium', $attr); ?> <div class="clearer"></div></a>
                	 <?php } ?>
  5. scottsweb
    Member
    Plugin Author

    Posted 6 months ago #

    Try this:

    <?php if (is_mobile()) { ?>
    					<?php $attr = array(
                            'title'	=> 'meer info over '.get_the_title(),
                            'width' => 390,
                            'height' => 'auto'
                        ); ?>
                    	<a href="<?php the_permalink(); ?>" title="Meer info over <?php the_title();?>"><?php the_post_thumbnail('medium', $attr); ?> <div class="clearer"></div></a>
    
                    <?php } else if (is_tablet()) { ?>
    					<?php $attr = array(
                            'title'	=> 'meer info over '.get_the_title(),
                            'width' => 187,
                            'height' => 256
                        ); ?>
                        <a href="<?php the_permalink(); ?>" title="Meer info over <?php the_title();?>"><?php the_post_thumbnail('small', $attr); ?> <div class="clearer"></div></a>
                    <?php } else { ?>
    					<?php $attr = array(
                            'title'	=> 'meer info over '.get_the_title(),
                            'width' => 187,
                            'height' => 256
                        	); ?>
                        <a href="<?php the_permalink(); ?>" title="Meer info over <?php the_title();?>"><?php the_post_thumbnail('medium', $attr); ?> <div class="clearer"></div></a>
                	 <?php } ?>
  6. inTOWN
    Member
    Posted 6 months ago #

    Thank works perfect, thank you scott... I had been a late night that I couldn't get through the conditional... I am deeply ashamed but you saved me!

  7. scottsweb
    Member
    Plugin Author

    Posted 6 months ago #

    My pleasure & good luck with the website :)

  8. solosails
    Member
    Posted 5 months ago #


  9. solosails
    Member
    Posted 5 months ago #

    Hi, is there a solution to the first question?

    How do you add several conditions together?

    Ie if is mobile device or tablet or ... for example?

    Many thanks. Andrew

  10. scottsweb
    Member
    Plugin Author

    Posted 5 months ago #

    Sure. You should be able to group conditionals like so:

    if (is_mobile() || is_tablet()) {

    If its not detecting your current device, it may be because the detection library needs updating. Give this early release a try: https://github.com/scottsweb/mobble/archive/master.zip

    Let me know how you get on.

  11. solosails
    Member
    Posted 5 months ago #

    Hi there,

    Thanks. That was how I had it but it wasn't working with the tablet I have (Asus Google Nexus 7 with Jelly bean OS)

    I have tried your new library, but it still doesn't seem to work. However, it does with my mobile (ios7)

    Any ideas? Cheers, Andrew

    I'm trying to get the 'Ticker Tape' Section of my website to not show on mobile and small screen devices as it scrolls the page down when it overflows.

    sailmakers

  12. scottsweb
    Member
    Plugin Author

    Posted 5 months ago #

    There are a couple of potential problems.

    1. Make sure your website does not use caching - any caching that skips PHP will not work with mobble.
    2. Give one of these a try:

    is_handheld() - to capture all handheld devices
    is_mobile() || is_tablet() || is_android - a tricky one as and you can also have Android based TVs these days - but it should work for the majority of use cases.

  13. solosails
    Member
    Posted 5 months ago #

    Hmm, still not working.

    I thought it was because I had an exclamation mark on the first like so...

    if (!is_mobile() || is_tablet()) {

    But if I take this away, it stops working with the mobile.

    If I have t set as above, it works with the mobile, but not the tablet, if I take the exclamation mark away it doesnt work with the mobile, if I keep the exclamation mark and add any more that above it stops working with the mobile!...?

  14. solosails
    Member
    Posted 5 months ago #

    Ok,

    using just...

    if (!is_handheld()) {...}

    seems to get it working on all devices. I guess I was having problems because I was trying to tell it NOT to do something, so that might change the way you list multiple conditions?

    Thanks for your help, A

  15. scottsweb
    Member
    Plugin Author

    Posted 5 months ago #

    Excellent. There is also an is_desktop() function which you may find useful too.

  16. solosails
    Member
    Posted 5 months ago #

    Hi,

    Yes, to work at it the other way around!

    Many thanks, Andrew

  17. mindctrl
    Member
    Posted 5 months ago #

    Hey Scott, there is no is_desktop() conditional here or in the Github repo.

  18. scottsweb
    Member
    Plugin Author

    Posted 5 months ago #

    Good spot! I must have been sipping something strong that day.

    Use the check !is_handheld() to assume a desktop device.

    Apologies.

Reply

You must log in to post.

About this Plugin

About this Topic