Where is the Wordpress content page created?

I am trying to create a search page in wordpress. In search.php, I can create most of the page, but then the next statement (which I got on the original page uneditted) generates the content.

<?php /* Include the Post-Format-specific template for the content. * If you want to overload this in a child theme then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> 

This ALMOST displays the page the way I want it, but there are several elements on the page, which makes it extensible, etc. I canโ€™t figure out which file generates this content!

Using the instructions, I created content-search.php and changed the line of code to this ...

 get_template_part( 'content', get_post_format() ); 

What works ... but it doesnโ€™t show anything, because I donโ€™t know what to put on my page within the scope of the original.

Does anyone have a key?

+4
source share
1 answer

You can use part of the template called post-search.php and you can use it in the search.php file, for example

 get_template_part( 'post' , 'search') 

but you need to create a php file inside the theme folder and name it post-search.php , and inside this file just set the WordPress loop ie

 <?php while (have_posts()) : the_post(); ?> <div class="post-entry clearfix"> <!-- Main wrapper --> <div class="post-entry-content"> <!-- Post-entry-content --> <h2><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <div class="post-entry-date">Posted on <?php the_time('F Y') ?> with <?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></div> <?php the_excerpt(); ?> <a href="<?php the_permalink(' ') ?>" class="post-entry-read-more" title="<?php the_title(); ?>">Read More ?</a> </div><!-- END of post-entry-content --> </div><!--End of main wrapper --> <?php endwhile; ?> 

and your .php search might be something like this

 <?php get_header(' '); ?> <div id="post-wrap"> <div id="post-content"> <?php if (have_posts()) : ?> <?php get_template_part( 'post' , 'search') ?> // This will load/include the file post-search.php and result will be displayed as formatted in this file <?php else : ?> <p>Sorry, it does not exist !</p> <?php endif; ?> </div><!-- END post-conten --> <?php get_sidebar(' '); ?> </div><!-- END post-wrap --> <?php get_footer(' '); ?> 

This is just an example, change the div / h2 id / class names to suit your css theme.

Note. . I am currently using this approach on one of my sites, and I have one file named "post-entry.php" in my theme folder and in every template file (index .php, search.php, etc. ) I just use this file, calling

 <?php get_template_part( 'post' , 'entry') ?> 
+6
source

Source: https://habr.com/ru/post/1403469/


All Articles