Välkommen till bloggen om design, webbutveckling och annat nyttigt! Med erfarenhet i skorna delar vi gärna med oss av det vi kan.

Med erfarenhet i skorna ser vi till att leverera bara med hög kvalitet.

En snabb översikt över användbara koder i WP

Important
Create wordpress@domain.com on server.
Or change wordpress to desired name in pluggable.php located in Includes folder.

Url rewrite fix for custom post types
insert into functions.php

add_action('init', 'my_rewrite');
function my_rewrite() {
global $wp_rewrite;
$wp_rewrite->add_permastruct('typename', 'typename/%year%/%postname%/', true, 1);
add_rewrite_rule('typename/([0-9]{4})/(.+)/?$', 'index.php?typename=$matches[2]', 'top');
$wp_rewrite->flush_rules(); // !!!
}

Target the first/last child
Javascript

$(document).ready(function(){
$("ul li:first-child").addClass("first");
$("ul li:last-child").addClass("last");
});

Target the odd child
Javascript

$(document).ready(function(){
$("li:odd").addClass("odd");
});

Rename admin menu lables
inserrt into functions.php

add_filter( 'gettext', 'change_post_to_article' );
add_filter( 'ngettext', 'change_post_to_article' );

function change_post_to_article( $translated )
{
$translated = str_replace( ‘Post’, ‘Article’, $translated );
$translated = str_replace( ‘post’, ‘article’, $translated );
return $translated;
}

Post thumbnai as background

ID) ); ?>

Create own shortcodes
hämtas så [btn url=#]label[/btn] (skriv button istället för btn)

function button_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'url' => 'button',
), $atts ) );
return ‘‘ . $content . ‘‘;
}

add_shortcode(‘button’, ‘button_shortcode’);

Show 2nd level menu separately in WordPress 3

if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>

Conditional excerpt length
add to functions.php

add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {
if(in_category(14)) {
return 13;
} else {
return 60;
}
}

Change ”W”-logo in dashboard
add to functions.php / images size 30×31

add_action('admin_head', 'my_custom_logo');

function my_custom_logo() {
echo ‘

‘;
}

Change wp-logo on login screen
add to functions.php

function my_custom_login_logo() {
echo '

‘;
}

add_action(‘login_head’, ‘my_custom_login_logo’);

Remove menus in Dashboard
add to functions.php

function remove_menus () {
global $menu;
$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}
}
add_action('admin_menu', 'remove_menus');

Header image

// Check if this is a post or page, if it has a thumbnail, and if it's a big one
if ( is_singular() &&
has_post_thumbnail( $post->ID ) &&
( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
$image[1] >= HEADER_IMAGE_WIDTH ) :
// Houston, we have a new header image!
echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
else : ?>


Conditional Custom fields

ID, 'Camera_Specs', true);
if ($camera_specs) {
?>

No specification available.

Edit link

', '

'); ?>

Log out

Default Usage
" >Logout
Logout and Redirect to Current Page
" >Logout
Logout and Redirect to Homepage
" >Logout

Get specific post by ID

$post_id = 70;
$queried_post = get_post($post_id);
?>

post_content; ?>

Conditional content

if (is_page('6')){
echo "

Case 1

”;
} else if (is_page(‘7′)){
echo ”

Case 2

”;
} else {
echo ”

Case 3

”;
}
?>

Shortcode for Contact form 7


Exclude pages


Filter search by categories

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("s=$s&paged=$paged&cat=24,25,26,27");
endif; ?>

Get Custom field


ID, $key, true); ?>

or

ID, "Camera_Specs", true); ?>

Get different sidebars


Links


Get RSS-Feed

include_once(ABSPATH . WPINC . '/feed.php');
$rss = fetch_feed('http://www.blogg.se/feed/');
$maxitems = $rss->get_item_quantity(1);
$rss_items = $rss->get_items(0, $maxitems);
?>

Create searchform.php

 

The Loop




or