GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech How to limit the number of wordpress posts just for mobile ? (https://gfy.com/showthread.php?t=1280541)

maidenphoenix 09-29-2017 08:41 AM

How to limit the number of wordpress posts just for mobile ?
 
I am using WPscript and I want to limit the number of posts for the mobile version of the website.

So far I found this code and placed it in the functions.php file. It doesn't do anything, I think it should be placed elsewhere. Any ideas?
Code:


add_action('pre_get_posts','change_limit_mobile');

function change_limit_mobile($query){

    $new_limit = 10;

    $iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
    $android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
    $ipad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
    $berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
    $ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");

    if (( $iphone || $android || $ipad || $ipod || $berry ) && $query->is_main_query()){
        set_query_var('posts_per_page',$new_limit);
    }
}


Denny 10-03-2017 12:13 AM

Bump for you.

Barry-xlovecam 10-03-2017 07:32 AM

change 10 to 5 and see what happens?

maidenphoenix 10-03-2017 08:25 AM

Quote:

Originally Posted by Barry-xlovecam (Post 22023265)
change 10 to 5 and see what happens?

Changed it, nothing happened.

magneto664 10-03-2017 08:36 AM

you are planing to change it for archive / category listing? well can be done by custom coding (not a big) with good mobile detection plugin.
for example https://wordpress.org/plugins/custom-content-shortcode/ this plugin can do this.

Barry-xlovecam 10-03-2017 10:20 AM

PHP Code:

set_query_var('posts_per_page',$new_limit); 

.

Have you tried

search => https://stackoverflow.com/questions/...ust-for-mobile he says this worked ;)

maidenphoenix 10-03-2017 11:07 AM

Quote:

Originally Posted by magneto664 (Post 22023349)
you are planing to change it for archive / category listing? well can be done by custom coding (not a big) with good mobile detection plugin.
for example https://wordpress.org/plugins/custom-content-shortcode/ this plugin can do this.

Thanks, I will check this. I am considering a global solution that would change both categories and archives to a predefined number of posts. I want to increase the advertising potential for mobile and displaying over 20 posts reduces earnings.

Quote:

Originally Posted by Barry-xlovecam (Post 22023507)
PHP Code:

set_query_var('posts_per_page',$new_limit); 

.

Have you tried

search => https://stackoverflow.com/questions/...ust-for-mobile he says this worked ;)

This is exactly where I got the code and it's not working for me. As I aforementioned I am using the WPscript theme.

magneto664 10-03-2017 12:14 PM

Quote:

Originally Posted by maidenphoenix (Post 22023621)
I want to increase the advertising potential for mobile and displaying over 20 posts reduces earnings.

So then use mobile detection plugin and inject on the top of the category or under the title or on the bottom a mobile / pc version of the ads. I do always it for mobile version i put widget area with 300x250 advert just under the category title.

tnx.

Smart Fred 10-07-2017 10:07 AM

For my logo I use CSS to display a different one according to the width size of the screen.

.logo1 {display:block;}
.logo2 {display:none;}
@media (min-width: 1150px) {
.logo1 {display:none;}
.logo2 {display:block;}
}

Then in the header I put both logo
<div class="logo1"><img src="logo1.png" width="118px" height="50px" /></div>
<div class="logo2"><img src="logo2.png" width="500px" height="80px" /></div>

If you do something similar for your blog content you should be able to get what you want using a different WP_Query in the two loops
https://codex.wordpress.org/Class_Reference/WP_Query


All times are GMT -7. The time now is 06:05 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc