get_the_content_feed()
Получает контент текущей записи в цикле фида. Используется в цикле.
Эта функция копия функции the_content(), с той лишь разницей, что текст обрабатывается еще и фильтром the_content_feed, а не только the_content.
Если контент записи для фида, нужно вывести на экран, используйте the_content_feed().
Работает на основе: get_the_content()
1 раз — 0.001937 сек (очень медленно) | 50000 раз — 8.21 сек (быстро) | PHP 7.0.8, WP 4.6.1
Хуки из функции
Возвращает
Строку. Контент записи для использования в фиде.
Использование
get_the_content_feed( $feed_type );
- $feed_type(строка)
Тип фида: rss2 | atom | rss | rdf.
По дефолту используется результат функции get_default_feed() почти всегда это - rss2. Это значение также можно изменить через фильтр:
$default_feed = apply_filters( 'default_feed', 'rss2' );
По умолчанию: null (rss2)
Примеры
#1 Вывод контента в теге <item>
<?php
$content = get_the_content_feed('rss2');
if( strlen( $content ) > 0 ){
?>
<content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
<?php }else{ ?>
<content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>
<?php
}
?> #2 Полный код тега <item>
Взято из файла: wp-includes/feed-rss2.php
<?php
/**
* Fires at the end of the RSS2 Feed Header.
*
* @since 2.0.0
*/
do_action( 'rss2_head');
while( have_posts() ){
the_post();
?>
<item>
<title><?php the_title_rss() ?></title>
<link><?php the_permalink_rss() ?></link>
<?php if ( get_comments_number() || comments_open() ){ ?>
<comments><?php comments_link_feed(); ?></comments>
<?php } ?>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
<dc:creator><![CDATA[<?php the_author() ?>]]></dc:creator>
<?php the_category_rss('rss2') ?>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<?php if (get_option('rss_use_excerpt')){ ?>
<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
<?php }else{ ?>
<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
<?php $content = get_the_content_feed('rss2'); ?>
<?php if ( strlen( $content ) > 0 ){ ?>
<content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
<?php }else{ ?>
<content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>
<?php } ?>
<?php } ?>
<?php if ( get_comments_number() || comments_open() ){ ?>
<wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2') ); ?></wfw:commentRss>
<slash:comments><?php echo get_comments_number(); ?></slash:comments>
<?php } ?>
<?php rss_enclosure(); ?>
<?php
/**
* Fires at the end of each RSS2 feed item.
*
* @since 2.0.0
*/
do_action( 'rss2_item' );
?>
</item>
<?php
}
?>
Заметки
- Смотрите: get_the_content()
Список изменений
| С версии 2.9.0 | Введена. |
Код get_the_content_feed() get the content feed WP 6.8.3
function get_the_content_feed( $feed_type = null ) {
if ( ! $feed_type ) {
$feed_type = get_default_feed();
}
/** This filter is documented in wp-includes/post-template.php */
$content = apply_filters( 'the_content', get_the_content() );
$content = str_replace( ']]>', ']]>', $content );
/**
* Filters the post content for use in feeds.
*
* @since 2.9.0
*
* @param string $content The current post content.
* @param string $feed_type Type of feed. Possible values include 'rss2', 'atom'.
* Default 'rss2'.
*/
return apply_filters( 'the_content_feed', $content, $feed_type );
}