Change menu layout on certain width repsonsive design WordPress - wordpress

I'm developing an responsive WordPress theme.
On a regular computer (full-size) a menu is visiblie like:
<div id="header-menu" role="complementary">
<ul>
<?php wp_list_pages('title_li=&depth=1&link_before=<span>&link_after=</span>'); ?>
</ul>
</div>
On a certain width (for mobile devices and tablets I'd like to replace this menu with a menu like this one:
<div id="header-menu-mobile" role="complementary">
<form action="<?php bloginfo('url'); ?>" method="get">
<?php
$args1e = array(
'depth' => 1,
'child_of' => 0,
'selected' => 0,
'echo' => 1,
'name' => 'page_id');
wp_dropdown_pages( $args1e ); ?>
</form>
<script type="text/javascript"><!--
var dropdown = document.getElementById("page_id");
function onCatChange()
{
if ( dropdown.options[dropdown.selectedIndex].value > 0 )
{
location.href = "<?php echo get_option('home');
?>/?page_id="+dropdown.options[dropdown.selectedIndex].value;
}
}
dropdown.onchange = onCatChange;
--></script>
</div>
I could in the css for a certain width set "header-menu" to hidden... and make "header-menu-mobile" set to visible. I'm kinda tired in my head and there's probably a better solution to make this work.
Any ideas on how?
Kind regards
Johan

You are right about your CSS idea. Stick with it.
Use this standard CSS structure to make your website responsive.
/* Large desktop */
#media (min-width: 1200px) { ... }
/* Portrait tablet to landscape and desktop */
#media (min-width: 768px) and (max-width: 979px) { ... }
/* Landscape phone to portrait tablet */
#media (max-width: 767px) { ... }
/* Landscape phones and down */
#media (max-width: 480px) { ... }

try $_SERVER['HTTP_USER_AGENT'];
it tells you about user operating system and browser. You may frame your code accordingly
example -
if $_SERVER['HTTP_USER_AGENT'] == 'win 8'
echo $menu_for_windows ;
else if $_SERVER['HTTP_USER_AGENT'] =='opera mini'
echo $menu_for_mobile
and so on ..
also
$browser = get_browser(null, true);
echo $browser['platform'] ; exit;
can tell you the user platform

Related

flexslider on small screens

I'm using the Sparkling theme on a Wordpress site. The theme uses Flexslider within a div at the top of the page. Each slide contains an image along with a div containing a post title and excerpt.
The slider is built within header.php like in this function:
function sparkling_featured_slider() {
if ( is_front_page() && of_get_option( 'sparkling_slider_checkbox' ) == 1 ) {
echo '<div class="flexslider">';
echo '<ul class="slides">';
$count = of_get_option( 'sparkling_slide_number' );
$slidecat =of_get_option( 'sparkling_slide_categories' );
$query = new WP_Query( array( 'cat' =>$slidecat,'posts_per_page' =>$count ) );
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
echo '<li>';
if ( (function_exists( 'has_post_thumbnail' )) && ( has_post_thumbnail() ) ) :
echo get_the_post_thumbnail();
endif;
echo '<div class="flex-caption">';
if ( get_the_title() != '' ) echo '<h2 class="entry-title">'. get_the_title().'</h2>';
if ( get_the_excerpt() != '' ) echo '<div class="excerpt">' . get_the_excerpt() .'</div>';
echo '</div>';
echo '</li>';
endwhile;
endif;
echo '</ul>';
echo ' </div>';
}
}
endif;
And the resulting HTML looks like this:
<div class="top-section">
<div class="flexslider">
<ul class="slides">
<li>
<img width="1920" height="512" src="http://pathtoslider.jpeg"
class="attachment-post-thumbnail size-post-thumbnail wp-post-image"
alt="slide1"
srcset="pathstodifferentresolutions.jpg"
sizes="(max-width: 1920px) 100vw, 1920px" />
<div class="flex-caption">
<h2 class="entry-title">Tomatoes</h2>
<div class="excerpt">Knowledge is knowing that tomatoes are a fruit. Wisdom is knowing not to put them in a fruit salad.</div>
</div>
</li>
..more slides..
</ul>
</div>
</div>
<div class="container main-content-area">
By default it suppresses the flex-caption on small screens by setting display:none in a media query, but I want to display it, so I set the display to inline in my own media query.
This leads to another problem because the whole top-section div is the height of the image and there isn't necessarily room for the flex-caption.
I would like the bottom of the entry-title to be aligned with the bottom of the image, and the excerpt immediately below the image, which I accomplish like this:
#media (max-width: 768px) {
.flex-caption {
display: inline;
bottom: 0;
}
.entry-title {
position: absolute;
bottom: 0;
}
.excerpt {
position: absolute;
vertical-align: top;
}
}
but this doesn't resize the top-section div, so I'm overwriting the main-content-area.
I've tried lots of different things, including trying height:auto just about everywhere.
I can't figure out how the slider height is set. It seems to be within get_the_post_thumbnail. Is that the issue?
You can try setting image height in functions.php
function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ).

Need to show different logo in mobile and tablet devices

I am building an ecommerce site using this theme http://goo.gl/3BwG7R
I have changed the header to black and and have a light logo. When viewed on mobile and tablet I need the header to be white (native) and the logo to be dark.
I have failed to utilize the media queries to make this happen.
The theme has 2 header files, the main file calls the other files to display stuff.
*** MAIN HEADER ------------------
<div id="logo" class="positionleft"><?php if_logo(); // print the logo html ?></div>
--------------------------------------------
*** SECOND HEADER (called header-functions) -----------------
// print the logo html
if(!function_exists("if_logo")){
function if_logo(){
$logotype = if_get_option( THE_SHORTNAME . '_logo_type');
$logoimage = if_get_option( THE_SHORTNAME . '_logo_image');
$sitename = if_get_option( THE_SHORTNAME . '_site_name');
$tagline = if_get_option( THE_SHORTNAME . '_tagline');
if($sitename=="") $sitename = get_bloginfo('name');
if($tagline=="") $tagline = get_bloginfo('description');
if($logoimage == "") $logoimage = get_stylesheet_directory_uri() . "/images/logo.png";
?>
<?php if($logotype == 'textlogo'){ ?>
<h1><?php echo $sitename; ?></h1><span class="desc"><?php echo $tagline; ?></span>
<?php } else { ?>
<div id="logoimg">
<a href="<?php echo home_url( '/' ) ; ?>" title="<?php echo $sitename; ?>" >
<img src="<?php echo $logoimage ; ?>" alt="<?php echo $sitename; ?>" />
</a>
</div>
<?php } ?>
<?php
}
}
*** MAIN CSS --------------------------
#logo{margin-right:7px;padding:14px 10px ;}
#logo img{height:43px;}
#logo h1{margin-bottom:0px; letter-spacing:-1px;}
/* Menu */
#navigation{text-align:left;}
#topnav{
margin:0;
padding:0px 0 0 0px;
list-style-type:none;
overflow:visible;
position:relative;
float:right;
}
*** LAYOUT CSS ---------------------
#logo{text-align:center;margin:0px;}
#logoimg img{text-align:center;margin:0px auto; max-width:100%;}
Here is a quick mark up of what it would look like to use media queries with img rather than using a background image. I used divs instead of images, but it's the same concept. If you minimize the browser you will see the text change.
Use logo as a background with media query.
#media (min-width:769px){
#logo{
background-image: url(link/to/main/logo.png);
}
}
#media (max-width:768px){
#logo{
background-image: url(link/to/tablet/logo.png);
}
}
#media (max-width:480px){
#logo{
background-image: url(link/to/mobile/logo.png);
}
}

cakephp and form css

Hi all I'm trying to create a mobile site for a website I've already created and am using in file css.
i am trying to make the input boxes 10% of the screen height. how can I do this?
how can I make the login button taller?
here is the code from the view file
<?php echo $this->Html->docType('xhtml-trans'); ?>
<html>
<head>
<style>
body {
background-color:#ADD8E6;
height: 960px;
width: 640px;
}
table, td, th
{
background-color: #ADD8E6;
}
input
{
height:233%;
width:70%;
}
</style>
<title> <?php echo $title_for_layout; ?></title>
<?php echo $this->Html->css($stylesheet_used); ?>
</head>
<body>
<div id = "headertwo" style="background-image:url(<?php echo $this->webroot; ?>img/BannerGradient2.jpg);">
<center>
<?php echo $this->Html->image($image_used, array(
"alt" => "eBox",
'url' => array('controller' => 'Users', 'action' => 'login'))) ?>
</center>
</div>
<?php echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'login')));?>
<table border=0 style="width:640px;">
<tr>
<td >Username:
<?php echo $this->Form->input('username',array('label'=>false,));?></td>
</tr>
<tr>
<td>Password: <?php echo $this->Form->input('password',array('label'=>false,));?></td>
</tr>
</table>
<?php echo $this->Form->end('Login', array('width'=>100));?>
</div>
</body>
</html>
user1393064,
You're using XHTML Doctype rightnow which is not good practice now a days to achieve good result in Targeted Mobile Device.
Instead I recommend you to try HTML5 Doctype, like below...
<!DOCTYPE html>
Additionally for Mobile support you need to add Viewport Meta
<meta name ="viewport" content ="initial-scale = 1.0, user-scalable = no">
Then you define your CSS for INPUT
input { /* put your code here */ }
input#submit { /* put your style here */ }
I also suggest you to use CSS Media Query for your targeted Mobile Device & Screen.
#media screen and (max-width: 640px){
body{ /* put your style here */ }
form{ /* put your style here */ }
input{ /* put your style here */ }
input#submit{ /* put your style here */ }
}
For further help you can refer to this article http://www.yourinspirationweb.com/en/tips-tricks-how-to-optimize-a-website-for-mobile-devices/
1.
input
{
font-size:200%;
width:70%;
}
did not think about including the font-size in the input as I didn't think of it as text, duhhh

disable hover and active pseudo class for mobile devices

Is it possible to disable the hover and active pseudo classes for mobile devices only?
I've found this
html.touch {
/* Touch is enabled */
}
html.no-touch {
/* Touch is disabled */
}
Which seems pretty neat. But I can't get it to work.
The code is below, and you can test it here: http://jsfiddle.net/5qb2J/
<html>
<head>
<style type="text/css">
#button{background:url("http://www.webstuffshare.com/wp-content/uploads/2010/03/button3.jpg") no-repeat 0 0;display:block;width:201px;height:67px;}
#button:hover{background-position:0px -67px;}
#button:active{background-position:0px -134px;}
#button span{position:absolute;top:-99999999em;}
</style>
</head>
<body>
<a id="button" href="#"><span>this is foo</span></a>
</body>
</html>
edit
I'm using this now
<?php // detect mobile
$Mobile = FALSE;
if
(strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "android") ||
strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "webos") ||
strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "iphone") ||
strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "ipod") ||
strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "ipad") ||
strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "zune"))
{
$Mobile = TRUE;
}
?>
and
<?php
If ($Mobile == FALSE)
{
echo <<<escapethis
some html here
escapethis;
}
?>
the lines that use the word escapethis can not begin with a space
Sounds like html.touch and html.no-touch are being used with a feature detection library like modernizr, which will do all sorts of feature testing and add classes to the html element based on the results of those tests.
In that case, you would want to do something like this:
html.no-touch #ElementThatShouldHaveNoHoverEventOnTouchDevices:hover{
//do your stuff
}
<div id="ElementThatShouldHaveNoHoverEventOnTouchDevices">
hello
</div>

wordpress creating a full-width dashboard widget

How can I create a full-width dashboard widget in WordPress?
I want to create a widget like the new one "welcome" in WordPress 3.3.
That plugin is in dashboard.php in wp_welcome_panel() but I don't know how they show it full-width.
They create a div "welcome-panel" outside the main div where all the widgets go, "dashboard-widgets-wrap":
<div id="welcome-panel" class="welcome-panel"></div>
<div id="dashboard-widgets-wrap">
<div id="dashboard-widgets" class="metabox-holder">
<div id="postbox-container-1" class="postbox-container" style="width:50%;">
<div id="postbox-container-2" class="postbox-container" style="width:50%;">
<div id="postbox-container-3" class="postbox-container" style="display:none;width:50%;">
<div id="postbox-container-4" class="postbox-container" style="display:none;width:50%;">
</div>
How can I achieve that?
Edit
I've found in wp-admin/index.php in line 90 this:
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php echo esc_html( $title ); ?></h2>
<?php wp_welcome_panel(); ?>
<div id="dashboard-widgets-wrap">
<?php wp_dashboard(); ?>
<div class="clear"></div>
</div><!-- dashboard-widgets-wrap -->
</div><!-- wrap -->
So they do it inserting directly the code.
The only solution I see is maybe using jQuery?
Any other option?
A full-width widget can be very useful for adding content at the top of your own themes with updates or corroborative info or anything.
Starting with WordPress 3.5.0, you can directly modify the welcome panel:
First remove the existing content, then add your own function to render the content:
remove_action( 'welcome_panel', 'wp_welcome_panel' );
add_action( 'welcome_panel', 'my_custom_content' );
function my_custom_content()
{
?>
<h1>Hello!</h1>
<?php
}
I was able to achieve this goal by modifying the admin css as below:
add_action('admin_head', 'panfor_admin_custom_styles');
function panfor_admin_custom_styles() {
$output_css = '<style type="text/css">
#media only screen and (min-width: 800px) and (max-width: 1499px) {
#dashboard-widgets #postbox-container-1 { width: 100% !important; }
#dashboard-widgets #postbox-container-2 { width: 50% !important; }
#dashboard-widgets #postbox-container-3 { width: 50% !important; }
}
#media only screen and (min-width: 1500px) and (max-width: 1800px) {
#dashboard-widgets #postbox-container-1 { width: 100% !important; }
#dashboard-widgets #postbox-container-2 { width: 50% !important; }
#dashboard-widgets #postbox-container-3 { width: 50% !important; }
}
</style>';
echo $output_css;
}
The above code enforces full width for all widgets in the first column of Dashboard for certain screen widths. The second and third columns are displayed below first colum.
This is what it looks like in my Dashboard
So it is not the widget as such that determines its width, but the css styles.
There is still a small problem in my CSS that I cannot solve. Namely, the second and third columns switch places, depending on the width of the window.
Unfortunately, there's no way to hook into that Welcome panel.
I've got two solutions for this.
Manipulating the div with CSS and jQuery
or
Injecting an iframe
In this case, I'm cleaning all the dashboard widgets, tabs, welcome panel. Forcing a one-column layout. And finally filling the void with the iframe.
But this can be easily adapted to suit your taste.

Resources