You get a bonus - 1 coin for daily activity. Now you have 1 coin

How to display news from a specific category in WordPress? cat doesn't help

Practice




How to display news from a specific category in WordPress? cat doesn't help
and how to display a short excerpt of the news in WordPress

in the news output template (on the left panel - Appearance menu, Editor, find the needed template on the right)

$news_categ = $wp_query->queried_object->name; //find out the current category in WordPress


if ( get_query_var('paged') ) {
$paged = get_query_var('paged'); //find out the current page during pagination in WordPress
} else if ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}

$news_pag = of_get_option('pag_news');

$news_categ='Категория1';
/* query arguments */
$args_news = array(
"post_type" => "news",
"news_categories" => $news_categ, //DISPLAY all news from the Категория1 category in WordPress
"posts_per_page" => $news_pag,
'post_status' => 'publish'
,"paged" => $paged//,
// 'category_name'=>'Категория1' won't work
// ,'cat'=>11
);

global $more;
$more = 0; ?>







echo "

".$news_categ."

"; } ?>







if (have_posts()) : while (have_posts()) : the_post();
$news_thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'news-thumb'); ?>





How to display news from a specific category in WordPress? cat doesnt help" class="news-img" />







  


// the_content('read more', 'framework'); /// if you need to display the full news post
the_excerpt(); // if you need to display a short news preview, the text is taken from the excerpt or automatically truncated from the full post
?>
Подробнее...














Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)