Created
December 29, 2010 09:21
-
-
Save bjrn/758362 to your computer and use it in GitHub Desktop.
add to functions.php
This file contains hidden or 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 | |
//add excerpt field to pages as well, and not only posts: | |
function my_page_excerpt_meta_box() { | |
add_meta_box( 'postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'page', 'normal', 'core' ); | |
} | |
add_action( 'admin_menu', 'my_page_excerpt_meta_box' ); | |
//add Facts box to all pages | |
function my_facts_meta_box() { | |
add_meta_box( 'facts', __('Vidste du at'), 'facts_meta_box', 'page', 'side', 'core' ); | |
} | |
function facts_meta_box(){ | |
global $post; | |
wp_nonce_field( 'facts', '_facts_nonce', false, true ); | |
$facts = get_post_meta( $post->ID, 'facts', true); | |
$facts_textile = get_post_meta( $post->ID, 'facts_textile', true); | |
if ($facts_textile=="" && $facts!="") $facts_textile=$facts; | |
?> | |
<p> | |
Tekst (formatteres med <a href="#" onclick="jQuery('#textile-help').slideToggle(); return false;" title="Vis kort hjælp om hvordan textile virker...">Textile</a>)<br> | |
<textarea name="facts_textile" id="facts_textile" rows="6" cols="20" style="width:99%"><?php echo attribute_escape( $facts_textile ); ?></textarea> | |
</p> | |
<div id="textile-help" style="display:none;"> | |
<p style="margin-top:0"> | |
bulletlister skrives på folgende måde:<br><br> | |
* text<br /> | |
* text <small style="color:#999">etc.</small><br /> | |
<br /> | |
dobbelt linieskifte for at afslutte liste<br /><br /> | |
<code>fed *tekst*</code> → fed <strong>tekst</strong><br /> | |
<code>kursiv _tekst_</code> → kursiv <em>tekst</em><br /> | |
</p> | |
<p><a href="http://textile.thresholdstate.com/" target="_blank">Læs mere om textile</a></p> | |
<p> | |
<small style="color:#999;font-size:10px">Debug - her vises teksten konverteret til HTML</small> | |
<textarea name="facts_contents" disabled="disabled" id="facts_contents" rows="3" cols="20" style="width:99%;font-size:11px; color:#ccc"><?php echo attribute_escape( $facts ); ?></textarea> | |
</p> | |
</div> | |
<?php | |
} | |
function facts_save_meta_box( $post_ID ) { | |
if ( wp_verify_nonce( $_REQUEST['_facts_nonce'], 'facts' ) ) { | |
//$facts = $_POST['facts_contents']; | |
$facts_textile = $_POST['facts_textile']; | |
$textile = new Textile; | |
$facts = $textile->TextileThis($facts_textile); | |
if ( isset( $_POST['facts_textile'] ) && strlen( $_POST['facts_textile'] ) > 0 ) { | |
update_post_meta( $post_ID, 'facts', $facts ); | |
update_post_meta( $post_ID, 'facts_textile', $facts_textile ); | |
} else { | |
delete_post_meta( $post_ID, 'facts' ); | |
delete_post_meta( $post_ID, 'facts_textile' ); | |
} | |
} | |
return $post_ID; | |
} | |
add_action( 'admin_menu', 'my_facts_meta_box' ); | |
add_action("save_post", 'facts_save_meta_box', 10, 2); | |
add_action("preview_post", 'facts_save_meta_box', 10, 2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment