A
A
Alexander2018-02-24 18:34:50
WordPress
Alexander, 2018-02-24 18:34:50

How to display article announcements on a separate Wordpress page?

Hello dear community members. Can you please tell me how to display the announcements of articles on a separately created page?
I created a new template for the page by copying the code from page.php
This is how the code looked originally:

<?php get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>

<?php if ( comments_open() || '0' != get_comments_number() )
comments_template();
?>

<?php endwhile;  ?>

</div>
</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

I added the function query_posts('category_name=camps'); before while. The result is this design:
<?php query_posts('category_name=camps'); while ( have_posts() ) : the_post(); ?>

In my case "camps" is the category slug.
Everything works, but the articles are displayed in expanded form (entirely), and I need them to look like announcements, as when filtering by headings. I've been googling all day but haven't been able to find anything clear
. Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Teploukhov, 2018-02-24
@radiozima

I would just replace your loop with something like this

<?php
  if ( have_posts() ){
    query_posts('category_name=camps');
    while ( have_posts() ){
      the_post();
      echo '<div class="post-item"><p><span class="post-title">' . get_the_title() . '</span></p>'; // Название статьи

      
      echo '<p class="post-min_content">' .get_the_excerpt(). '</p>'; // миниатюра статьи (то что вам нужно)

      echo '<div class="open-post"><a href="'. get_permalink() .'" class="link-post">Читать</a></div></div>'; // Ссылка на полную версию поста
    }
  }
  else{
    echo ' <p>Записей нет...</p>';
  }
?>

just a piece from a blog that I did, so substitute your html markup.

O
Orkhan Hasanli, 2018-02-24
@azerphoenix

Hello.
Google will not help here) See the template for your topic. Most likely, entries with announcements are displayed in archives or categories. Accordingly, look for archive.php category.php taxonomy.php Here you can find the method they use to output excerpts. And so the standard method
<? php the_excerpt (
)
?

A
Alexander, 2018-02-24
@radiozima

I thank comrades Konstantin Teploukhov and azerphoenix . Thanks to their answers, the desired function was independently found. It get_template_part( 'content', 'search' );'s in search.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question