Query WordPress Categories

Webmaster WordPress Leave a Comment

Query Category Posts for WordPress  This query_posts() is a way to query categories and display post from inside any WordPress template. <php query_posts(‘cat=72&showposts=4’); ?> Place the post query before the post opening php in a theme template file. Example: <php query_posts(‘cat=72&showposts=4’); ?> <php if (have_posts()) : ?>

Remove the ul class from the wp_nav_menu

Webmaster WordPress Leave a Comment

Removes the ul class from the wp_nav_menu Place the code below into your themes functions.php template between the <?php. // Removes ul class from wp_nav_menu function remove_ul ( $menu ){return preg_replace( array( ‘#^<ul[^>]*>#’, ‘#</ul>$#’ ), ”, $menu );}add_filter( ‘wp_nav_menu’, ‘remove_ul’ );

Remove div container class from the wp_nav_menu

Webmaster WordPress Leave a Comment

Removes the div container class from the wp_nav_menu Place the code below into your themes functions.php template between the <?php. // Removes div class from wp_nav_menu add_filter(‘wp_nav_menu_args’, ‘prefix_nav_menu_args’);function prefix_nav_menu_args($args = ”){$args[‘container’] = false;return $args;}

Remove li class & ID from wp_nav_menu

Webmaster WordPress Leave a Comment

Removes the li class & ID from wp_nav_menu Place the code below into your themes functions.php file between the <?php. // Removes li classes & ID’s from wp_nav_menu add_filter(‘nav_menu_css_class’, ‘my_css_attributes_filter’, 100, 1); add_filter(‘nav_menu_item_id’, ‘my_css_attributes_filter’, 100, 1); add_filter(‘page_css_class’, ‘my_css_attributes_filter’, 100, 1); function my_css_attributes_filter($var) {   return is_array($var) ? array() : ”; } // Removes particular classes & ID’s from wp_nav_menu function my_css_attributes_filter($var) {   return is_array($var) ? array_intersect($var, array(‘current-menu-item’)) : ”;}

Alternate WordPres Single.php

Webmaster WordPress Leave a Comment

Alternate single post template for posts in specific categories. Here’s the simplest way to use alternative single post templates for all post in specific categories. Add this code to the top of the single.php template. Edit the category number and template path to match your alternative template location and the category it’s intended for. <?php$post = $wp_query->post;if (in_category(4)) {include (TEMPLATEPATH.’/example.php’);return;} if (in_category(73)) {include (TEMPLATEPATH.’/example1.php’);return;} if (in_category(12)) {include (TEMPLATEPATH.’/example2.php’);return;}  if (in_category(5)) {include (TEMPLATEPATH.’/example3.php’);return;}?>

Logged In/Out Only Content

Webmaster WordPress Leave a Comment

Use the scripts below to show and hide content to logged in or logged out users in WordPress. Only logged out WordPress users can see this. <?php if (!is_user_logged_in() ) { //only logged in user can see this ?>content<?php } ?> Only logged in WordPres users can see this. <?php if (is_user_logged_in() ) { //only logged in user can see this ?>content<?php } ?>

Domain Alias Redirecting

Webmaster WordPress Leave a Comment

Redirect domain alias (subdomains) with WordPress using the .htaccess file. This also fixes problems wordpress has using subdomains as main URL. You may be using www. or uk. or any other subdomain as your main wordpress URL, this .htaccess  hack converts all domain aliases not used as blog url to reside frontend of your main url. Example: uk.elance.me/wordpress would redirect use SEO friendly techniques to www.elance.me/wordpress/?source=uk.elance.me. Domain alias are usually a  (301 cloak) and shows the visited subdomain including url string and …