Search view in wordpress

Asked

Viewed 196 times

3

Speaks friends,

I wonder if you have any way to display the research done on a wordpress site in this way:

Post = in the "x" format, and, Page = in the format "y"

thanks!

  • 1

    You got a little confused your question, you can explain it a little better?

  • @Danielcosta man, so.. I did a survey... the display is standard for pages and posts. I want when a WP page appears, to appear in a rectangle. And when post I want it to appear in square... Ai example, I searched on "Rice"... I have 2 pages that talk about rice and 3 posts that tbm talk about rice... The display I want is the following... Rice - Rectangle, Rice - Rectangle, Rice - Square, Rice - Square, Rice - Square. I don’t know if I can do this with a simple "if"... If(page){ Rectangle Display} Else if(post){ Square View}

1 answer

6


In the search.php file of your theme in Wordpress, you can use the method get_post_type(); to check the content type of the post.

Example:

<?php
get_header();
if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();
        //verifica se é post ou página
        if (get_post_type() == "page") {
            //exibe título da página em um retangulo
            echo "<div class='retangulo'>";
            the_title();
            echo "</div>";
        }
        else if (get_post_type() == "post") {
            //exibe título do post em um quadrado
            echo "<div class='quadrado'>";
            the_title();
            echo "</div>";
        }
    }
}
  • Vlw friend! It’s simpler than I imagined.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.