Display only one category on home page

display only one category on home pageWell nowadays I found that there are many people looking for a plugin, snippet or hack to control displaying posts on the home page. This is snippet focused on displaying posts on the homepage from chosen category or categories.

So here is the snippet code or hack, now you just have to paste the code below in your functions.php file. Please be sure that you paste the code under the php tags.
 

 

 

PHP – Display only one category on home page

[php]
function my_category_queries( $query ) {
// only homepage and is the main query
if ($query->is_home() && $query->is_main_query()){
// display only posts in category with slug ‘articles’
$query->set(‘category_name’, ‘articles’);
// avoid sticky posts
$query->set(‘post__not_in’, get_option( ‘sticky_posts’ ) );
}
}<br />
add_action( ‘pre_get_posts’, ‘my_category_queries’ );

[/php]

Conclusion:
As you can see at the beginning of the function we are using the conditional functions is_home() witch is used for The Main Page and is_main_query() Is Main Query witch affect only to the main loop, and the function will proceed if both of conditions are true.
[php]$query->is_home() && $query->is_main_query()[/php]

The first $query-> ensures that all the posts are displayed with the category slug articles, this includes all Sticky Posts with any category, too.
[php]$query->set(‘category_name’, ‘articles’)[/php]

But then with the second $query-> set it to get all the posts with the category slug articles except for the posts that are sticky posts.
[php]$query->set(‘post__not_in’, get_option( ‘sticky_posts’ ) )[/php]

Additional notes:

Category Parameters
[php]
cat (int) – use category id.
category_name (string) – use category slug (NOT name).
category__and (array) – use category id.
category__in (array) – use category id.
category__not_in (array) – use category id.
[/php]

Let’s explain those parameters on our example now, well the first two commands works pretty same but the difference is that on first one we use Category ID’s and second one slugs. So basically if we wish to query the posts from two categories on the homepage we can simply update the code to ‘articles,affiliate-programs’ and function will call posts from the both categories on the homepage loop.

PHP – Display multiple categories on homepage

[php]
function my_category_queries( $query ) {
// only homepage and is the main query
if ($query->is_home() && $query->is_main_query()){
// display only posts in category with slug ‘articles’
// and slug ‘affiliate-programs’
$query->set(‘category_name’, ‘articles,affiliate-programs’);
// avoid sticky posts
$query->set(‘post__not_in’, get_option( ‘sticky_posts’ ) );
}
}

add_action( ‘pre_get_posts’, ‘my_category_queries’ );
[/php]

The example will be with the cat command instead of category_name will look like example bellow where the 25 and 36 are the category id’s.
[php]$query->set(‘cat’, ‘25,36’);[/php]

Different Background on each WordPress Post or Page

You may want to have a different background on your WordPress website. For example, you may have a celebrity blog and want to include an image of that celebrity on each of there pages or you may have a site that covers different topics and want to have a different color to represent each category.

This is easy to do with the plugin called Background Per Page.

Simply (in your WordPress dashboard) go to Plugins > Add New and search for Background Per Page, or download Background Per Page plugin, extract and upload the folder to the /wp-content/plugins/ directory. Then just Activate the plugin trough ‘Plugins’ menu in WordPress.

Download Background Per Page

How to Add Google AdSense into WordPress Part 2

In Part 1 I showed you how to add Google AdSense into your WordPress widgets. In part 2 I will show you how to add Google AdSense directly into your theme templates.

This means once its added it will continually add you code directly into each new page or post. In Part 3 i will show you which AdSense plugins are the best to use.

List of UK Towns, Cities & Counties for WordPress Categories & Database

Lots of people are forever searching the web for a list of UK towns, cities and counties.

Once they find it they are then stuck on how to use this info in there WordPress installation.

I have put together a video guide along with a CSV file for you to download all in the correct format for you to use straight away. it will take you know more than 5 minutes to use.

First off you can download a copy of the UK Towns, Cities and Counties Database Free Here.

You’ll need this free plugin, Go to Plugins > Add New and search for this in your WordPress dashboard WPEssence Bulk Categories

 

How to Add Google AdSense into WordPress Themes Part 1

Over a few tutorials i will show you how to add Google AdSense directly into your theme.
In Part 1 i will show you a really simple way to add your Adsense into a widgeted area. Then in part 2 i will show you how to add it directly into a theme file e.g. so that it adds AdSense directly into every post you make.

This is the YouTube video i have created showing you how to do this, If you find it useful please like it, add a positive comment for me and share it on your social network. All your support is appreciated.

Top WordPress Plugins (free)

When you install your WordPress website you will want to add some WordPress plugins.

These are the recommended plugins you should add to every site to get you started…

Contact Form 7

By far the most popular contact form plugin. Simple to use and an absolute must if you want people to be able to contact you. See an example here.

Yoast SEO

Want to be found by the search engines? Not an SEO expert? Don’t worry, this WordPress SEO plugin (from one of the most respected SEO’s in the world) is free and easy to install and makes your onpage SEO really easy with a simple check list. It also autogenerates you an XML sitemap (for posts, pages, categories and images) that you can add to Google Webmaster Tools.

seo

Related Posts via Categories

Blogs generally have a high bounce rate (a user visits one page then leaves the website). This is because they have found the information they want then leave your website. This plugin suggests other posts they may like and keeps them on on your website.

ShareThis

With everyone using social media these days (Facebook, Twitter etc) you need to make it easy for your users to share your content and this plugin does exactly that.

YouTube Sidebar Widget

If you have created YouTube videos for your blog then you need a YouTube plugin to add your video thumbnails to your sidebar.

All in One Adsense and YPN Pro

Have a Google AdSense account? This plugin makes it quick and easy for you to set up your website monetization. (Adsense account required)

Google Analytics for WordPress

Another awesome plugin from Joost de Valk (WordPress SEO Plugin creator). Track your sites visitors activity with this easy to use plugin. Google Analytics account required.

That should be enough to get you started, and don’t forget to change your Settings > Permalinks to post tag so you get SEO friendly URLs 😉

Parse error: syntax error, unexpected T_VARIABLE in wpincludes /functions.php on line 192 WordPress 3.5

There seems to be a lot of people experiencing a problem after upgrading to WordPress 3.5

If you get the following error (or very similar)

Parse error: syntax error, unexpected T_VARIABLE in wpincludes /functions.php on line 192

Then it is believed your wordpress upgrade has been hacked.
This has now been confirmed as a definite hack. To confirm, YOUR WEBSITE HAS BEEN HACKED!

You can review this forum for help on fixing this error

Some people are simply replacing the functions.php file with a new copy of this file, however there is likely to be a number of files in your root directory (take a look for files that just start with a load of numbers)

It is recommend (strongly recommended) to fix this error permanently and to remove the hackers files from your website that you work through the following resources. (I can help if required but i do charge $100 for this as its a lot of work)

Ill update this post when a patch from wordpress is released or further advice is received.

Best WordPress Tag Plugins & Widgets

With so many plugins available for WordPress its often frustrating trying to find the one you want to do the thing you need it to do.

I’m creating a list of the best WordPress Tag Plugins here. I’ll add more to it as i find and use more myself. Feel free to add a comment on the ones you like.

Taxonomy List Widget

If you want to show a list of your Tags with the number of times they have been used in list format then this plugin does that for you. You can simply add it as a widget to any widget-ed area like a sidebar.

Ultimate Tag Cloud Widget

If you prefer a Tag Cloud then the Ultimate tag cloud widget is the one for you. When you hover over the tag it also shows the number of times you have used that tag across all your posts.

Moving WordPress Sidebar from Right to Left Twenty Twelve Theme

In WordPress Twenty Twelve Theme many people find it difficult to move the sidebar from the right side to the left side.

Well it is easy if you know how and i have put together instructions along with a video for this for you.

Simply add this code to the bottom of your style.css file and save and refresh your page to see the changes.

/*– move sidebar to the left fix by wperror.com –*/
@media screen and (min-width: 600px) {
.site-content {
float: right;
}
.widget-area {
float: left;
}
}

/* for IE8 and IE7 —————-*/
.ie .site-content {
float: right;
}
.ie .widget-area {
float: left;
}

If you are not using the Twenty Twelve them then try using this code instead of the above code

@import url(‘../twentytwelve/style.css’);

/*– move sidebar to the left fix by wperror.com –*/
@media screen and (min-width: 600px) {
.site-content {
float: right;
}
.widget-area {
float: left;
}
}

/* for IE8 and IE7 —————-*/
.ie .site-content {
float: right;
}
.ie .widget-area {
float: left;
}

Still unsure, then watch this video.