Подтвердить что ты не робот

Правильный способ получения содержимого страницы

Я должен получить определенное содержимое страницы (например, page (12))

Я использовал это:

  <?php $id=47; $post = get_page($id); echo $post->post_content;  ?>

Work nice, кроме совместимости с переводами, возвращает текст на французском и английском языках

Но с циклом все в порядке, верните только версию на хорошем языке

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div id="post">
<?php the_content(); ?>
</div> <!-- .post -->

Итак, вопрос.... КАК получить конкретное содержимое страницы внутри цикла...

4b9b3361

Ответ 1

Я ответил на свой вопрос. Вызовите apply_filter и там вы идете.

<?php 
$id=47; 
$post = get_post($id); 
$content = apply_filters('the_content', $post->post_content); 
echo $content;  
?>

Ответ 2

получить содержимое страницы по названию страницы:

<?php
$page = get_page_by_title( 'page-name' );
$content = apply_filters('the_content', $page->post_content); 
echo $content;
?>

Ответ 3

Я использовал это:

<?php echo get_post_field('post_content', $post->ID); ?>

и это еще более кратким:

<?= get_post_field('post_content', $post->ID) ?>

Ответ 4

Простой, быстрый способ получить содержимое по id:

echo get_post_field('post_content', $id);

И если вы хотите получить отформатированный контент:

echo apply_filters('the_content', get_post_field('post_content', $id));

Работает со страницами, сообщениями и настраиваемыми сообщениями.

Ответ 5

Просто скопируйте и вставьте этот код, чтобы получить содержимое своей страницы.

<?php
                $pageid = get_the_id();
                $content_post = get_post($pageid);
                $content = $content_post->post_content;
                $content = apply_filters('the_content', $content);
                $content = str_replace(']]>', ']]&gt;', $content);
                echo $content;
                ?>

Ответ 6

Функция wp_trim_words также может ограничить символы, изменив переменную $num_words. Для тех, кто может оказаться полезным.

<?php 
$id=58; 
$post = get_post($id); 
$content = apply_filters('the_content', $post->post_content); 

$customExcerpt = wp_trim_words( $content, $num_words = 26, $more = '' );
echo $customExcerpt;  
?>

Ответ 7

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'prev_text' >' Previous','post_type' => 'page', 'posts_per_page' => 5, 'paged' => $paged );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post();
//get all pages 
the_ID();
the_title();

//if you want specific page of content then write
if(get_the_ID=='11')//make sure to use get_the_ID instead the_ID
{
echo get_the_ID();
the_title();
the_content();
}

endwhile;

//если вы хотите определенную страницу содержимого, тогда пишите в цикл

  if(get_the_ID=='11')//make sure to use get_the_ID instead the_ID
    {
    echo get_the_ID();
    the_title();
    the_content();
    }

Ответ 8

Один вкладыш:

<? if (have_posts()):while(have_posts()): the_post(); the_content(); endwhile; endif; ?>