Last active
October 13, 2015 09:28
-
-
Save alisspers/4174719 to your computer and use it in GitHub Desktop.
WordPress 3.5 för oss utvecklare – kodexempel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Exempel: Temascript som använder sig av WP:s bundlade Backbone.js | |
wp_enqueue_script( | |
'my-app', | |
get_template_directory_uri() . '/js/app.js', | |
array( 'backbone' ) | |
); | |
// Handle för Underscore.js är föga förvånande 'underscore' | |
wp_enqueue_script( | |
'my-app', | |
get_template_directory_uri() . '/js/app.js', | |
array( 'underscore' ) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Jag vill hämta ut posterna med ID 11, 9 och 13 i given ordning | |
query_posts( | |
array( | |
'post__in' => array( 11, 9, 13 ), | |
'orderby' => 'post__in', | |
) | |
); | |
while ( have_posts() ) | |
{ | |
the_post(); | |
echo get_the_ID() . '<br>'; | |
} | |
/* Output: | |
11 | |
9 | |
13 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function register_my_event() | |
{ | |
// Registrera en ny CPT som exempel | |
register_post_type( | |
'my_event', | |
array( | |
'label' => 'Event', | |
'public' => true, | |
) | |
); | |
// Skapa taxonomi och lägg till den i admintabellen | |
register_taxonomy( | |
'event_type', | |
'my_event', | |
array( | |
'label' => 'Type', | |
'hierarchical' => true, | |
'show_admin_column' => true, // Detta gör att "Type" hamnar i admintabellen | |
) | |
); | |
} | |
add_action( 'init', 'register_my_event' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment