web hosting
build a website
Browsing articles from "August, 2015"

PHP select which part of text/name to output using array

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

The below is saying if the $prodName has ~ in it then add in the second part of the name array in instead.

<?php
                    $prodName = $_helper->productAttribute($_product, $_product->getName(), 'name');
                    if (strpos($prodName, '~') !== FALSE){
                        $pieces = explode("~", $prodName);
                        $prodName = $pieces[1];
                    }
                ?>

PHP replace a string in an array with a string

Aug 15, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

The below code sets getImageUrl as the variable $baseimageurl it then gets anything in $baseimageurl uses it in an array and says if it is a http:// or https:// replaces it with a blank “”

So what this means is if $baseimageurl starts with http:// or https:// it removes it so that the link will probably only start as www.

$baseimageurl = $_product->getImageUrl();
echo "\n&viewed-image=" . str_replace(["http://", "https://"],"",$baseimageurl);

Create a url rewrite in Magento

Aug 15, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

To create a url rewrite in Magento go to:

  • Catalog > url rewrite management
  • Add new url rewrite
  • Custom

Request path is the page name that you want to redirect from and don’t need trailing slashes, the ID path is the same as the request path and the target path is where we want to redirect to e.g. if we want to redirect http://www.devinesdesign.com/index.php/news/ to http://www.devinesdesign.com/blog/
we would have the following:
IDpath = news
request path = news
target path = http://www.devinesdesign.com/blog/
Redirect = Permanent 301

I put the full link in for my target path because with my site if I had just put in blog for the target path the link would of been http://www.devinesdesign.com/index.php/blog/ and I did not want this as my blog is not on Magento it is on wordpress and my wordpress installation does not have index.php in the link.

This should work straight away but if not do a cache clear in magento backend.

Image issues when moving Magento site to new domain and Server

Aug 15, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

Moving Magento site from one server to another and under a different domain name you may find that images in your media folder cache are missing, for me the issue was on my basket page. To fix this make your media folder chmod 777. Then in the media folder delete the .htaccess file, then in Magento admin flush cache storage and flush Magento cache. This should fix the issue.

Add specific post to a page on wordpress

Aug 15, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

The below code adds a specific post to a page on WordPress and it outputs the title and content:

<?php
$post_id = 18;
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
echo $title;
echo $queried_post->post_content;
?>

Add feature image of posts to WordPress homepage

Aug 15, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

The below code Adds thumbnails, title and text snippet onto homepage of WordPress if you use a feature image on your post, it then sets the width and height to 100 x 100. It also shows only posts from category 1 and limits the amount to 5 posts.

<div id="portfoliothumbs">
<?php query_posts('cat=1&showposts=5'); ?>
<?php if(have_posts()) : ?>
     <?php while(have_posts()) : the_post(); ?>
          <div class="post"> 
               <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
               <div class="entry">	
                    <?php the_content(); ?>
                    

<div class="thumbnail">
    <?php the_post_thumbnail( array(100,100) ); ?>
    </div>
              </div>
          </div>
     <?php endwhile; ?>
<?php endif; ?>
</div>

WordPress relative link to template folder

Aug 15, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

In Wordppress you may want to link an image or css file in your theme directory to your site like the logo or main style sheet. Instead of adding in an absolute link into your php file which includes your domain name you can use the following code for a relative link. This is much better as you may end up changing your site domain name. I found it very useful as I would usually create a site under a test domain before moving it over to the new one.

<?php bloginfo('template_directory');?>/styles.css
Pages:«12