숏코드 샘플링

add_action( ‘init’, ‘register_shortcodes’);

function register_shortcodes(){
add_shortcode(‘recent-posts’, ‘recent_posts_function’);
}

function recent_posts_function() {
query_posts(array(‘orderby’ => ‘date’, ‘order’ => ‘DESC’ , ‘showposts’ => 1));
if (have_posts()) :
while (have_posts()) : the_post();
$return_string = ‘‘.get_the_title().’‘;
endwhile;
endif;
wp_reset_query();
return $return_string;
}

참고: 위의 숏코드 등록 함수와 아래의 initialization action을 하나로 통합하여 아래와 같이 함수 파일에 추가해도 동일한 결과가 나옵니다.

add_shortcode('recent-posts', 'recent_posts_function');

<iframe src="<?php echo get_stylesheet_directory_uri(); ?>/subdirectory/my-source-page.php">

my-source-page.php이제 이렇게 보입니다 :

<?php 
// First we get the home path where WP lives
$path = preg_replace('/wp-content.*$/','',__DIR__);

// Then we load WP's core functionalities
require_once( $path . '/wp-load.php');

// And we can now use WP's core functions.
if ( is_user_logged_in() ) { ?>

<!doctype html>
<html>
    <head></head>
    <body>
        Some content.
    </body>
</html>

<?php } ?>

[khs-ifrmae-page]