1. phpMyAdmin
2. robimy backup
3. aby dodać własne pole do wszystkich wpisów i stron, robimy zapytanie:

INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID AS post_id, 'OwnCustomField'
AS meta_key 'myvalue AS meta_value FROM wp_posts
WHERE ID NOT IN (SELECT post_id FROM wp_postmeta WHERE meta_key = 'MonCustomField');

4. aby dodać własne pole tylko do wpisów:

INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID AS post_id, 'MyCustomField'
AS meta_key 'myvalue AS meta_value
FROM wp_posts WHERE ID NOT IN
(SELECT post_id FROM wp_postmeta WHERE meta_key = 'MonCustomField')
`` AND post_type = 'post';

5. aby dodać własne pole tylko do stron:

INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID AS post_id, 'MyCustomField'
AS meta_key 'myvalue AS meta_value
FROM wp_posts WHERE ID NOT IN
(SELECT post_id FROM wp_postmeta WHERE meta_key = 'MonCustomField')
AND `post_type` = 'page';

thx 2 thecustomizewindows.com

WordPress developer at work

w functions.php dodajemy:

function get_content_link( $content = false, $echo = false )
{
if ( $content === false )
$content = get_the_content();

$content = preg_match_all( '/hrefs*=s*["']([^"']+)/', $content, $links );
$content = $links[1][0];

if ( empty($content) ) {
$content = false;
}

return $content;
}

używamy w templacie jako np.:
<h2><a href="<?php echo get_content_link( get_the_content() ); ?>"><?php the_title(); ?></a></h2>
<p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>">Comment »</a>

dzięki http://wp-snippets.com

WordPress developer at work

<?php $values = get_post_custom_values("nazwa_pola"); // nazwa pola własnego
if (isset($values[0])) { // jeśli wartość pola jest pusta
?>

<?php $values = get_post_custom_values("reference_link"); echo $values[0]; ?>
<?php } // Jeśli wartość pola jest pusta zastąp to poniższą wartością
else { ?>
inne niż puste
<?php } ?>


<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>

functions.php:


if (function_exists('register_sidebar')) {


register_sidebar(array(
'name'=> 'Górny Sidebar',
'id' => 'gorny_sidebar',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
register_sidebar(array(
'name'=> 'Lewy Sidebar',
'id' => 'lewy_sidebar',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
register_sidebar(array(
'name'=> 'Prawy Sidebar',
'id' => 'prawy_sidebar',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
}

sidebar.php np. prawy sidebar):
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Prawy Sidebar')) : ?>
[ funkcja, która się wywoła, gdy widżet nie istnieje ]
<?php endif; ?>

sidebar-left.php np. lewy sidebar):
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Lewy Sidebar')) : ?>
[ do default stuff if no widgets ]
<?php endif; ?>

Tradycyjnie w functions.php jedziemy:
<?php
// Post list shortcodes
function wptuts_post_lists_sc( $atts, $content = null, $tag ) {
global $post;
$post_ID = $post->ID;
$post_author = $post->post_author;
extract( shortcode_atts( array(
'number' => 5,
'exclude_current' => 'yes',
'orderby' => 'date'
), $atts ) );
$args = '';
switch( $tag ) {
case "latest_posts":
// we don't need any arguments to retrieve latest posts :)
break;
case "category_posts":
$categories = get_the_category( $post_ID );
$first_category = $categories[0]->term_id;
$args = 'cat=' . $first_category;
break;
case "author_posts":
$args = 'author=' . $post_author;
break;
case "future_posts":
$args = 'post_status=future';
break;
}
$not_in = '&post__not_in[]=' . $post_ID;
if ( $exclude_current == 'no' )
$not_in = '';
$get_posts = get_posts( $args . $not_in . '&posts_per_page=' . $number . '&orderby=' . $orderby );
$output = '<ul class="' . $tag . '">';
foreach ( $get_posts as $post ) {
$output .= '<li><a href="' . get_permalink() . '" title="' . esc_attr( get_the_title() ) . '">' . get_the_title() . '</a></li>';
}
$output .= '</ul>';
wp_reset_query();
return $output;
}
add_shortcode( 'latest_posts', 'wptuts_post_lists_sc' );
add_shortcode( 'category_posts', 'wptuts_post_lists_sc' );
add_shortcode( 'author_posts', 'wptuts_post_lists_sc' );
add_shortcode( 'future_posts', 'wptuts_post_lists_sc' );
?>

Stworzyliśmy shortcode’y:
[latest_posts]
[category_posts]
[author_posts]
[future_posts]

Używamy je wraz z 3 wariacjami: cat, author, post_status