• Resolved pmdci

    (@pmdci)


    Hello there,

    I am wondering if there is a way to differentiate the results of a searchpage based on if they are pages or posts?

    I would like to use a different CSS class for page entries and post entries. Is this possible?

Viewing 8 replies - 1 through 8 (of 8 total)
  • You could wrap you posts in a div called say “entry” and then your pages “page_entry” and then style them differently. But then they might look different on the pages and blog section as well. Perhaps you could insert a different style sheet when you are on the search page?

    Thread Starter pmdci

    (@pmdci)

    Crondeu,

    Thank you for the message.

    I think that instead of calling different CSS, I would like to wrap each type in a different div. I suppose I would have to call the function to query entries two times: one time to fetch pages, and a second time to fetch posts. Is this correct?

    Or perhaps there is a better way to do it? like a conditional for each returned item?

    How is this possible? Is it isn’t much to ask, could you kindly help me with some sample code?

    Thank you for the help.

    Regards,
    P.

    hi pmdci,

    to apply a different css to pages and posts, simply isntall the great Classy Body Plugin ( https://www.alistercameron.com/2007/01/04/wordpress-plugin-classybody/ ). this will add extra classes to the BODY tag, and based on this, you can create different styles for absolutely ANY individual page, post, archive, categorym etc.

    it`s an excellent plugin!

    Thread Starter pmdci

    (@pmdci)

    hi andiszek,

    Don’t think this plug-in would work for me. What is to differ pages and posts in the search results page. for example, if I search for “lorem ipsum”, and the search results page return three items. Two posts and one page:

    <div class="thisisapost">Lorem Ipsum Post #1</div>
    <div class="thisisapage">Lorem Ipsum Page</div>
    <div class="thisisapost">Lorem Ipsum Post #2</div>

    Now I was wondering if there is a way to do this when calling the function to return the results? Perhaps first the function should be called to return only posts wraped in the class “thisisapost”, followed by a second call to return only pages werapped in the class “thisisapage”.

    Is there a way to do this?

    Thanks,
    P

    SOLVED!!! I wanted to do the same thing, and after looking at the functions page in the Codex, I found the solution. (Note, this works on Version 2.8.4, the latest version at the time of this post.)

    <?php if(get_post_type($post) == "page") : ?>
    
    <!-- Page Preview -->
    
    <?php else : ?>
    
    <!-- Post Preview -->
    
    <?php endif; ?>

    Awesome! dwighthouse’s solution above still works in 2.9.2 in case anyone was wondering…

    Thread Starter pmdci

    (@pmdci)

    Hi dwighthouse!

    Thanks a lot for posting the answer! I completely forgot about this one because, well, I thought it was a lost cause!

    Thank you once again!

    Thread Starter pmdci

    (@pmdci)

    FYI, my idea is to use this procedure to separate search results into tabs.

    [Pages] [Post] {Custom Post Type 1] [Custom Pages 1] [ETC…]

    Any idea if there is a plug-in that could help with this? I know a plug-in that can be used but in the post editor (when editing pages, posts, etc) and it works with shortcodes. Now for in this case, since I plan to edit the template file… humm… Any ideas of a tutorial or something like that?

    Cheers,
    P.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘searchpage.php – different css for page and for post’ is closed to new replies.