Showing posts with label Wordpress Tips. Show all posts
Showing posts with label Wordpress Tips. Show all posts

Not Found The requested URL was not found on this server

Sometimes, when you migrate a website from other server to your local server for testing or development and try to run this on browser.

You get an error message like
Not Found
The requested URL was not found on this server
Not Found The requested URL was not found on this server


You check all configurations. Everything is OK in all configuration files of your website. But still you get same error message.

Actually i faced this issue when i run my website on newly installed wamp server. I have searched on google. After spending long time i got a solution and i want to share with you.

It's very simple. I am sharing you two methods. Check which one is working for you.

Method 1.

In apache folder, open httpd.conf file and search following line

#LoadModule rewrite_module modules/mod_rewrite.so

Remove # from the beginning of the line, after removing # line will look like this:

LoadModule rewrite_module modules/mod_rewrite.so


If above method didn't work for you then try method 2.

Method 2.

Change this

Include conf/extra/httpd-vhosts.conf
to

#Include conf/extra/httpd-vhosts.conf
and restart all services


I am sure your issue will be solved...


Read More

How to retrieve data from feed using php

If you want to get data from feed and show on your website. There are few steps to follow.

s2pfeedparser

Requirement:


  1. Localhost (Xampp/Wamp) or Online host
  2. Feed url something like http://feeds.feedburner.com/ours2ptech . It may be different
  3. Basic knowledge php
  4. Some time (30 Mins)


  • If you have fulfill all requirement. Then lets try to make a feed parser. I am taking example of retrieving BBC news from feed.
  • If you are running localhost. Then start xampp or wamp.
  • I have a BBC new feed like http://feeds.bbci.co.uk/news/rss.xml. When you open this link. You will not see its data in xml format. You can see it by view source.
  • Click Ctrl+u on keyboard. You can see its xml.
  • Now you are ready to start. Follow these steps


  1. Create a folder in htdocs. You can give any name. For example s2pfeed.
  2. Create a page index.php . I write php codes in this page.
  3. We are retrieving data from other websites or feeds. So i am using curl. This is the best way to carry data from other websites. We can use php inbuilt class SimpleXmlElement to extract xml data.
  4. Flow chart: FeedUrl ----- Curl data ---- Data array

try{
$ch = curl_init("http://feeds.bbci.co.uk/news/rss.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
}
catch(Exception $e)
{
  echo 'Invalid Feed';
  //exit;
}
Before move to next step. Check carefully source code of feedurl. You will see something like following
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/shared/bsp/xsl/rss/nolsol.xsl"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>BBC News - Home</title>
<link>http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>
<description>The latest stories from the Home section of the BBC News web site.</description>
<language>en-gb</language>
<lastBuildDate>Wed, 19 Feb 2014 20:57:35 GMT</lastBuildDate>
<copyright>Copyright: (C) British Broadcasting Corporation, see http://news.bbc.co.uk/2/hi/help/rss/4498287.stm for terms and conditions of reuse.</copyright>
<image>
<url>http://news.bbcimg.co.uk/nol/shared/img/bbc_news_120x60.gif</url>
<title>BBC News - Home</title>
<link>http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>
<width>120</width>
<height>60</height>
</image>
<ttl>15</ttl>
<atom:link href="http://feeds.bbci.co.uk/news/rss.xml" rel="self" type="application/rss+xml"/>
<item>
<title>Blair 'advised Brooks before arrest'</title>
<description>Former Prime Minister Tony Blair gave advice to News International boss Rebekah Brooks on handling the developing phone-hacking scandal days before her arrest, a court hears.</description>
<link>http://www.bbc.co.uk/news/uk-26259956#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>
<guid isPermaLink="false">http://www.bbc.co.uk/news/uk-26259956</guid>
<pubDate>Wed, 19 Feb 2014 16:24:51 GMT</pubDate>
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/73083000/jpg/_73083312_021157970-1.jpg"/>
<media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/73086000/jpg/_73086069_021157970-1.jpg"/>
</item>
<item><title>Ukraine president sacks army chief</title>
<description>Ukrainian President Viktor Yanukovych sacks the head of the armed forces, amid protests that have turned Kiev into a battle zone.</description>
<link>http://www.bbc.co.uk/news/world-europe-26265808#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>
<guid isPermaLink="false">http://www.bbc.co.uk/news/world-europe-26265808</guid>
<pubDate>Wed, 19 Feb 2014 20:09:37 GMT</pubDate>
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/73097000/jpg/_73097274_73097252.jpg"/> 
<media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/73097000/jpg/_73097275_73097252.jpg"/>
</item>
.
.
.
<item> ... </item>
 This is making chain like
xml
   channel
       title
       link
       description
       ...
       item
          title
          description
          link
          guid --- isPermaLink
          pubDate
          media --- thumbnail
  Item node represents individual post on feed.  Now come back to php coding.  Check above mentioned curl script.
$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);  
Here $doc is an instance carrying all data of xml.

If you want to get data of channel such as title, link, description and etc.

Use following code.
$title = $doc->channel->title;
$link = $doc->channel->link;
$description = $doc->channel->description;

If you want to retrieve single recent item (post) data

Use following code
$title = $doc->channel->item[0]->title;
$description = $doc->channel->item[0]->description;
$link = $doc->channel->item[0]->link;

You can retrieve all data.

But if you want to retrieve multiple recent post data

Use following code
$cnt = count($doc->channel->item); // this variable contains total number of posts showing in this feed
for($i=0; $i<$cnt; $i++)
    {
 $url  = $doc->channel->item[$i]->link;
 $title  = $doc->channel->item[$i]->title;
 $desc = $doc->channel->item[$i]->description;
 $pubDate = $doc->channel->item[$i]->pubDate;
     }
But you cannot retrieve node like
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/73083000/jpg/_73083312_021157970-1.jpg"/>

What can we do? Very simple. Do some tricks.

In this node, you have two things namespace (media) seperated by colon (:) and some attributes.

To retrieve data from namespaces media, Check the second line of feed source code.
<rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
Get url from media and url is http://search.yahoo.com/mrss/ .

Now your php code:

$media = $doc->channel->item[$i]->children('http://search.yahoo.com/mrss/')->thumbnail;
Is it return any value. Answer is no. Actually values are here in form of attributes.
So,
$thumb = $media->attributes();$thumburl = $thumb['url'];$thumbwidth = $thumb['width'];
Here in this feed there are multiple media. So you can use following code to retrieve media data
$thumbcount = count($media);
for($j=0;$j<=$thumbcount;$i++)
{
    $thumb = $media[$j]->attributes();
    $thumburl = $thumb['url'];
    $thumbwidth = $thumb['width'];
}
That's it.
Check complete code here:
<?php
try{
$ch = curl_init("http://feeds.bbci.co.uk/news/rss.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
}
catch(Exception $e)
{
  echo 'Invalid Feed';
  //exit;
}
$cnt = count($doc->channel->item); // this variable contains total number of posts showing in this feed
for($i=0; $i<$cnt; $i++)
    {
 $url  = $doc->channel->item[$i]->link;
 $title  = $doc->channel->item[$i]->title;
 $desc = $doc->channel->item[$i]->description;
 $pubDate = $doc->channel->item[$i]->pubDate;
$cnt = count($doc->channel->item); // this variable contains total number of posts showing in this feed
for($i=0; $i<$cnt; $i++)
    {
 $url  = $doc->channel->item[$i]->link;
 $title  = $doc->channel->item[$i]->title;
 $desc = $doc->channel->item[$i]->description;
 $pubDate = $doc->channel->item[$i]->pubDate;
                  $media = $doc->channel->item[$i]->children('http://search.yahoo.com/mrss/')->thumbnail;

$thumbcount = count($media);
for($j=0;$j<=$thumbcount;$i++)
{
    $thumb = $media[$j]->attributes();
    $thumburl = $thumb['url'];
    $thumbwidth = $thumb['width'];
}

     }
    }

?>
I think, this is a complete feed parser for you.
If you have any query. Please comment. I will try to give response as soon as possible.
Read More

Build a Custom WordPress Theme from Scratch

Today i am telling you how to make a custom wordpress theme from scratch. If you’re confident with your CSS and HTML, it’s not hard at all to step up to the challenge of building a custom WordPress theme.
Here is the screenshot of Wordpress theme which we'll make :

Overview of Wordpress main files :
  • header.php - Contains everything you'd want to appear at the top of your site.
  • index.php - The core file that loads your theme, also acts as the homepage (unless you set your blog to display a static page).
  • sidebar.php - Contains everything you'd want to appear in a sidebar.
  • footer.php - Contains everything you'd want to appear at the bottom of your site.
  • archive.php - The template file used when viewing categories, dates, posts by author, etc.
  • single.php - The template file that's used when viewing an individual post.
  • comments.php - Called at the bottom of the single.php file to enable the comments section.
  • page.php - Similar to single.php, but used for WordPress pages.
  • search.php - The template file used to display search results.
  • 404.php - The template file that displays when a 404 error occurs.
  • style.css - All the styling for your theme goes here.
  • functions.php - A file that can be used to configure the WordPress core, without editing core files.

These tags tell WordPress where to insert the dynamic content. A good example is the <?php the_title(); ?> tag, which pulls in the post title and displays it in your theme:
Your HTML code :
Click to Enlarge

Now we go to build wordpress theme and the first step to make style.css (Configuring the stylesheet)
All the details of a WordPress theme are contained within the stylesheet. At the top of your style.css add the following code, then amend the details to suit.
/*
Theme Name: Sticky
Theme URI: http://www.s2ptech.blogspot.com
Description: Sticky WordPress theme
Version: 1
Author: Mukesh Kumar
Author URI: http://www.geekonjava.blogspot.com
*/

Now come to header.php
Open up your header.php file, and paste in the head section from your concept HTML file. Then we need to go in and replace certain elements with the correct WordPress template tags to ensure it all works correctly.
Click to Enlarge

Now building the index.php
The next step is to flesh out the main body of the website. Open up the index.php file and paste in the main bulk of the concept HTML.
Click for Enlarge

Now time to sidebar.php
The sidebar in my design is where the list of pages and categories are held. The sidebar.php file was called from the index using the get_sidebar(); tag, so anything within this sidebar.php file is inserted into the theme in the right place
Click for Enlarge


Rounding off the footer.php
The footer.php file is probably the most simple file for this theme. The only thing that goes in here is the wp_footer(); tag just before the </body>, so that any extra info can be inserted in the correct place.
Click for Enlarge

Constructing the page and single view
WordPress is made up of posts and pages. Posts use the single.php template file, whereas pages use the page.php template file.

They're pretty much the same, apart from that you tend to include the comments_template(); tag for posts, and not for pages.

Creating the archive.php
The archive.php file is used to display a list of posts whenever they're viewed by category, by author, by tag etc.

It's basically the same as the index file, but with the addition of a tag at the very top that renders a useful page title, so the user knows where they are. 'Browsing the Articles category' for instance.


Your Final resulting theme would look like : Sticky Wordpress Theme
Read More

Run php page from any location on Localhost

As you know, If you want to run php pages using Xampp, You have to put your php pages under
htdocs folder.

But this is not necessary. You can put your files anywhere in your system.
Follow these steps to make this thing working:

If you are using Xampp

1. Open Xampp Control Panel, Click on "Config" button.

2. Then Click "Apache(httpd.conf)". A notepad will open.

If you are using Wamp

1. Goto apache --->  conf

2. Open "httpd.conf" with Notepad


3. Under this notepad, search for the term "DocumentRoot"

    You will see following line:
          
           DocumentRoot "C:/xampp/htdocs"
          <Directory "C:/xampp/htdocs">

4. Replace Red colored text with your desired path.

Now you can put your files under your desired path and you can run it successfully.

That's it.
Read More

Improve Wordpress page load using 3 Best Free Services

Most of people make a website but not take care about their page load and lose their visitors time by time.
Everyone knows that the speed of the blog is taken into account when ranking pages in the SERPs.
In this post, I will be discussing 3 best free services that you can use easily to speed up your WordPress blog.

You must read : Blogger V/s Wordpress
  • Google Speed Service:
 It is the simplest to configure. All you have to do is add the domain in Google Page Speed Service and it provide you with a CNAME which you have to add in the DNS settings of your WWW subdomain.

free services
Detailed data about the bandwidth, requests, traffic is shown in the Console API itself.You can also check out the official guide on how to use the pagespeed service here.

free services
It is provided for free but Google has plans to make this a premium service. So, you can still use it as long as it’s free.
  • CloudFlare:
Cloudflare is one of the best CDN services that you can use for free. You can also create a premium account but for normal blogs the free account is enough. Apart from CDN services, it also provides Security and Analytics Details. Now, let’s take a look at all the features of Cloudflare.
Cloudflare’s web content optimization is one of the best. It has loads of features like AutoMinify CSS and Javascript, Javascript Bundling, Asynchronous Loading, Local Storage Caching etc.
free services
AutoMinifying CSS and Javascript will compress your site’s Javascript and CSS files and results in faster loading. Javascript bundling makes sure multiple javascript requests are converted into a single request instead of multiple ones which results in faster page loading. Asynchronous loading enables your HTML part of the site to load fast without being delayed by slow loading widgets or scripts.
  • Incapsula
Like Cloudflare, Incapsula has identical features. It’s security features include protection against scraping, spam and preventing unauthorized access to both the backend and frontend of your site. It also has a premium plan which you can use if you’re looking to equip your site with more security.

free services
For a free plan, Incapsula offers more security than Cloudflare. It has a running Web Application Firewall which protects your site from SQL injections and other online threats. Another feature it has is DDoS protection which basically protects your site from Network and Application level threats.
It also consists of a CDN and an Optimizer which accelerates your site and makes loading atleast 40% faster. Like Cloudflare, it also has Analytics which monitors real time traffic and suspicious bots and sends you a detailed e-mail about the threats it has encountered.
Read More

Blogger Or Wordpress is better ?

Blogger and WordPress are best and popular blogging platforms today. More and more Internet users are going to use it. But the most confusing part is what to choose and why. So, here’s full comparison of Blogger and WordPress with all pros and cons.



Blogger :

  • Blogger is free blogging platform owned by Google. And the best part of Blogger is it’s completely free. As Well, it also provides free domain with extension blogspot.com. And you can also use your own custom domain with it. It’s extremely easy to setup and manage blogspot blog.
  • Publishing content is really easy with blogger. And you don’t need to backup database or anything. Allow you to display ads like Google Adsense and amazon, etc. As well as it’s completely ad free.
  • There are also some cons of blogger. Like, Maximum of 1GB Storage, No FTP support, Limitation of designing compared to WordPress and many more.

WordPress :

  • WordPress is Most Powerful and popular CMS (Content Management System) of all time. It’s divided in 2 parts : WordPress.com and WordPress.org self-hosted. WordPress.com is a hosted version of WordPress.org Providing free platform with limited features as well paid with premium features. I personally not recommended WordPress.com because most of the themes and plugins not working with free version.
  • WordPress.org is open source free software. Anyone can download WordPress software from wordpress.org and install on their server. It’s completely free and no limitation to use it. But you need to pay your hosting fees to your hosting provider.
  • Self hosted WordPress is very flexible since it’s open source. You can customize it as you want. You own it on your server so you have full control over it. You can use and install any free or premium themes and plugins on it. There are tons of themes and plugins available on web. It’s fully search engine friendly and you can also define your own custom meta tags. And it’s take less than 5 minutes to install it on your server.
Read More