0

As you can see of the webpage www.evolvedtools.org/Genr8PageIntro.php I fetch blogs from my wordpress.org blog and display them on this page using some simple php markup: In the page header:

<?php 
require('./blog/wordpress/wp-blog-header.php');
?>

...And in the page body:

<div id="PHPBlog">
<?php 
global $post;
$args = array( 'posts_per_page' => 8 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a><br >
<?php endforeach; ?>
<p>Feeds - Personal Blog - Master Thesis</p>
</div>

The problem is I only want the blog post to show when you are in full screen desktop. I have made media queries for different environments. I DONT WANT TO SHOW THE DATABASE CONTENT OTHER THAN UNDER THESE CONDITIONS:

<link href="TextPstyle.css" rel="stylesheet" type="text/css" media="only screen and (min-width: 41em)" id="stylesheet-TextP">

I know very little PHP so I've just started tinkling with these things. I would be very happy if anyone could advise me on this :-)

3
  • 1
    Use javascript to check user window size, and send a proper request to php server. Commented Jun 28, 2013 at 9:18
  • I know how to do the first, but sending a proper request to the server using javascript++ sounds difficult... Commented Jun 28, 2013 at 9:40
  • you can also define class inside media query and when that query is fired set that class visibility to none; Commented Jun 29, 2013 at 11:25

2 Answers 2

1

You could use $_SERVER['HTTP_USER_AGENT'] and search it for desktop operating systems and then conditionally execute some code:

function is_desktop() {
    $agent = $_SERVER['HTTP_USER_AGENT']
    // Code here to check for desktop
}

if (is_desktop()) {
    // Show conditional content
} else {
    // Otherwise
}

The reason you'd do this server side using PHP rather than client side using CSS is because the data should not be loaded at all (not loaded and then hidden) for non-desktop users.

EDIT

Of course, reusing someone else's code is a good idea. I've used Mobile_Detect before and you could make this check:

include 'Mobile_Detect.php';
$detect = new Mobile_Detect;
if ($detect->isMobile() || $detect->isTablet()) {
    // Handle mobile version
} else {
    // Handle desktop version
}
Sign up to request clarification or add additional context in comments.

4 Comments

I appreciate both answer and comment :-) Do I add the function to the php markup ? And what would I use to check for desktop there ? Like you say, I don't want data to be loaded on a tablet or a mobile phone!
I hope I am understanding correctly ? I add the markup client side, and if the condition for desktop is met, the blog posts are loaded ? Could I put a media query in there to check for the desktop ?
Again, I thank you for the contributions. After doing a bit of googling, I found the best way for me was to use js->clientwidth->window.location and redirect to html page without the php markup. Some of my pages I want to make lightweight for mobile browsers anyway, so maybe it's not a bad way to go ?
you could detect with JavaScript if you like, but checking for the screen size may not work if you minimise the screen on a desktop - it'll go to the mobile version.
0

Here is what i said in comment.

@media all and (min-width: 41em) {
.someclass
    {
        display:none;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.