Intro
I decided to create a topic for a script that create adaptive images. I have updated this topic so I can refer. Demand a more focused on a particular answer #ChrisFerdinandi advised me to use the script Adaptive Images+. This script would do exactly do what I'm looking for.
So I was looking for a script that checked me when the website is visited on a retina screen, like an iPad or iPhone for WordPress.
Problem
I will explain at every step what I did and share my code. Before I share my code and walk-through all steps, I will post some information about my WordPress installation.
I have installed my WordPress installation in a subfolder called /wordpress. I am using a custom WP theme, that I have developed on my own. I use featured images for my portfolio items. I create them in my function.php file like add_image_size('thumbnail-portfolio', 300, 200, true);
According to the installation page of the plugin from Chris Ferdinandi, we start by changing the .htaccess file in step 1. So, what I did is past everything between the comments #START Adaptive-Images and #END Adaptive-Images immediately after RewriteEngine On.
So my entire file would like this:
#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
#START Adaptive-Images
#Add any directories you wish to omit from the Adaptive-Images process on a new line.
#Omit plugins, wp-includes and wp-admin content.
RewriteCond %{REQUEST_URI} !wp-content/plugins
RewriteCond %{REQUEST_URI} !wp-includes
RewriteCond %{REQUEST_URI} !wp-admin
#Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
#to adaptive-images.php so we can select appropriately sized versions
RewriteRule .(?:jpe?g|gif|png)$ adaptive-images.php
#END Adaptive-Images
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
#END WordPress
Ok, after modifying the .htaccess file, I uploaded to the server. I update it inside the /wordpress subfolder. Fine that's done, let's go to step 2. This step I have skipped because this was an optional option.
Right step 3. I uploaded adaptive-images.php into the same directory as my .htaccess file, for clarity I have both files uploaded in the subdir. /wordpress.
Step 4. I add the cookie script right after the beginning <head> before all other scripts will run. My entire file looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title><?php bloginfo('name'); ?><?php wp_title('|'); ?></title>
<!-- Meta Tags -->
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<!-- Stylesheets -->
<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet">
<link href="<?php bloginfo('template_directory'); ?>/css/960.css" rel="stylesheet">
<link href="<?php bloginfo('template_directory'); ?>/css/flexslider.css" rel="stylesheet">
<link href="<?php bloginfo('template_directory'); ?>/css/isotope.css" rel="stylesheet">
<!-- JavaScript -->
<script>
document.cookie='resolution='+Math.max(screen.width,screen.height)+("devicePixelRatio" in window ? ","+devicePixelRatio : ",1")+'; path=/';
</script>
<script src="<?php bloginfo('template_directory'); ?>/js/jquery-1.8.1.min.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_directory'); ?>/js/custom.js"></script>
<script src="<?php bloginfo('template_directory'); ?>/js/jquery.flexslider.js"></script>
<script src="<?php bloginfo('template_directory'); ?>/js/jquery.isotope.js"></script>
<script src="<?php bloginfo('template_directory'); ?>/js/jquery.isotope.min.js"></script>
<?php
/* Always have wp_head() just before the closing </head>
* tag of your theme, or you will break many plugins, which
* generally use this hook to add elements to <head> such
* as styles, scripts, and meta tags.
*/
wp_head();
?>
</head>
Alright that's also done. In step 5. I have add the snippet of code to my css file.
Okay, the last step. Step 6 is testing all the stuff, here is probably the problem immediately clear. Since I have access to a mobile device retina, I decided first to look my site on that device. Unfortunately, only small resolution pictures shown, so that the image is not clear focus. I then looked as step 6 indicates that if there are really new images are created and stored/saved. There is an ai-cache folder created by the script adaptive-images.php, but this is unfortunately empty.
Something to notice, is that I have set the featured image size to the normal size and not to the retina version. So 300x200 is for default view, for retina would be the size 600x400px
What have I done?
I have checked the debug page of the script. I noticed that the cookie will be set as resolution. When I replace the line RewriteRule .(?:jpe?g|gif|png)$ adaptive-images.php in .htaccess to RewriteRule .(?:jpe?g|gif|png)$ test.png all images will be override by that one.
Error will be given after remove the comment before the error call. Every path is linking right.
I tried to change the permissions of the folder ai-cache from 755 to 777 with no results.
I've had great success with Adaptive Images, but it involves a bit of manual work. http://cferdinandi.github.io/adaptive-images/
I have found the easiest solution is to make one image -- twice the norm -- compress it, and call it on non retina displays at half its size.
See explanation here...
http://silev.org/test/Retina-resize.html
Related
No matter what I try, every single time I want to install FontAwesome into any project, it does not work and I have to try and figure out for many hours why not. What is going wrong here? I've put both the css and webfonts directory into the same directory called fontawesome. I've linked to those files and I literally tried everything I could think of:
URL with dots,
URL without dots,
no first slash,
with first slash,
HTML file,
PHP file,
Changing URLS in all.css (same as above) to point to the right path...
There is no icon showing, not even a 'missing icon' square. The file opened here is index.php and is located directly inside the admin directory (not in a subdirectory).
What am I missing here?
Use this cdn link and remove all other fontawasome cdn links
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
For Example :
<html>
<head>
<title>Demo</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
</head>
<i class="fa fa-address-book" aria-hidden="true"></i>
</html>
I'm porting an old site to a new template and am having problems with the Windows 2008 rewrite module. The link I'm trying to rewrite looks like this:
http://ltweb2008.serveronline.net/product.php?pID=75
and brings up the page just fine. Then I apply the new URL and it loads the proper content, but doesn't load the template's style.css file anymore.
http://ltweb2008.serveronline.net/product/75/any-text-here
The problem seems to be that the company who made the template (canvas) put the main .css file in the root directory, but loaded all the rest in /css. Now I can't get the main .css file to load using the rewrite and when I move it down to /css it only displays a blank page, though when I check out the page source it's all there.
With this the page shows but is not using style.css (with rewrite):
<link rel="stylesheet" href="style.css" type="text/css" />
With any of these the page is completely blank (with rewrite):
<link rel="stylesheet" href="/style.css" type="text/css" /> OR
<link rel="stylesheet" href="/css/style.css" type="text/css" /> OR
<link rel="stylesheet" href="http://ltweb2008.serveronline.net/style.css" type="text/css" />
I'm using this for the Pattern:
^product/([0-9]+)/([^/]+)$
And the Rewrite URL:
/product.php?pID={R:1}
Does anyone know what I'm missing?
one solution is that use absolute path (ex /css, or /js rather than just css/, /js but this is not looks a reliable solution since we've to change it on all files,
This is because your relative URIs have their base changed. Originally, the base is / when the page is /product.php?id=75, and the browser properly fills in relative links with the / base. But when the browser goes to a page like /product/75/any-text-here the base suddenly becomes /product/ and it tries to append that in front of all relative URLs and thus none of them load.
You can either make your links absolute, or change the URI base in the header of your pages (inbetween the <head> </head> tags):
<base href="/">
Maybe you need one thing, maybe both, I didn't test, but this solved it for me:
1.) ADD THIS in page_load :
Page.Header.DataBind() ' Needed because we have <%# %> codeblocks in the HEADER (seems header only causing this) WITH the AjaxControlToolkit running on the page. That's what broke it until we put in this and put in the pound instead of = sign in the html.
2.) Add this in ASPX:
<%# MasterType VirtualPath="~/dir1/dir2whateverdir/MasterPage.master" %>
I've successfully setup my theme and using it for the rest of my site on Magento 1.7, however the print order screen (http://<my-domain>/index.php/sales/order/print/order_id) seems to be ignoring local.css and using all of the styles from styles.css.
For example button.button span from styles.css is being used for the Close button when I have this in local.css and the rest of the site uses this. I've even tried to set a more specific selector but this gets ignored.
Is there something simple I'm missing on this screen as I haven't had this problem anywhere else.
Edit: Workaround solution: I viewed the source HTML of the page and can definitely see that local.css is not loaded anywhere in the page. On other pages I can see it being pulled in. Seems like a bug in Magento 1.7.0.2, so I copied /app/design/frontend/base/default/template/page/print.phtml to my template path(/app/design/frontend/default/<my-theme>/template/page/print.phtml) and fixed.
It seems this block isn't doing what it's meant to do and does in other pages
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
So in my copy of the file in my template directory I added the line below just before </head> which worked.
<link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('css/local.css') ?>" media="all" />
I logged a defect here: http://www.magentocommerce.com/bug-tracking/issue?issue=15841
I'm fixing this joomla site. It uses joomla 1.7 language filter so it adds post fixes to the url. So when i view an artcle with images, image is not displaying.
I tried htaccess rewrite rules. But it didn't work for me...
this is what i get when i copy image url.
http://domain.com/en/images/myimage.png
But when I check the code its images/myimage.png .
If i edit code to /images/myimage.png it works.
Tthis is what i try to do with htaccess too, to add a "/". Since it didn't work i guess i have to change whole url.
I don't have much knowledge in rewriting.
Can you guys help me please?
Give this a go in your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^.*/images/(.*)$ http://%{HTTP_HOST}/images/$1 [L,R=301]
</IfModule>
This will rewrite your /en/images/... requests to /images/...
Note, this could have unexpected consequences for other URLs. I would suggest properly testing this on your own application.
The .htaccess solution only works partially for me, so I fixed this from the template's index.php file.
Inside the <head> tag, after the <jdoc:include type="head" /> code I added this code
<?php
//removed joomla autogenerated <base> tag
unset($doc->base); ?>
<base href="<?php echo JURI::root(); ?>">
Tested with Joomla 3.6.5
In EE 2.2.2 having this in my htaccess file
RewriteRule ^(.*)$ /index.php/view/$1 [L]
Allowed me to rewrite domain.com/index.php/view/phone to domain.com/phone.
In EE 2.3.1 this no longer works. The problem seems to be with system\codeigniter\system\core\URI.php and I see few things has changed with this file. If I replace URI.php with the 2.2.2 version then it works again. My question is what has changed and how do I get this to work again.
Updated answer
After some time with thoughts (and testing) I've come up with an alternate solution, that might fit your need with the updated EE.
Assuming your rewrite rules are like the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Now, my suggestion is to let your view template group be the index template group.
In your index template in the view template group, you could have the following:
{exp:channel:entries channel="view_channel" require_entry="yes"}
{if no_results}
{embed="a_template_group/my_normal_frontpage"}
{/if}
<DOCTYPE html>
<html>
<head>
<title>{title}</title>
</head>
<body>
<h1>{title}</h1>
</body>
</html>
{/exp:channel:entries}
This allows you to, without adding other rewrite rules, have your visitors go to http://example.org/phone and the view/index template will try to find the entry with the entry ID labeled 'phone'. If that entry cannot be found (the {if no_results} part) embed another template. In this case I would assume you'd like to show some sort of frontpage.
This also allows you to, under the view template group, create ordinary templates like view/create_entry which will show up, when you go to http://example.org/create_entry
This should work - and is easy customizable to fit your needs.