Support » Fixing WordPress » Find out if page or post in SERP?

  • Hey guys,

    I’m sure I’ll work this out myself in the next few hours, but in my search results page I need to decipher whether the output loop contains just pages, just posts, or a mixture of both; and chuck out a suitable class to style off.

    I’m guessing category is quite important here..?

    Any help much appreciated – even some pseudo code would be awesome.

    Thanks!
    L

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ldexterldesign

    (@ldexterldesign)

    Well, I have this and it works. Would love some more intelligent input though :]

    <?php $category = get_the_category();
    // cat_ID 5, 6, and 7 are the only existing post categories presently
    if ($category[0]->cat_ID == 5 || $category[0]->cat_ID == 6 || $category[0]->cat_ID == 7){
    	echo 'post';} else{
    		// everything else is a page (because it doesn't have a category)
    		echo 'page';
    		}
    		// this method isn't very scalable is it :[ (e.g. if someone adds a new post category i'll have to update the if condition) ?>

    Thanks,
    L

    Can’t you use
    is_page() function !?

    Thread Starter ldexterldesign

    (@ldexterldesign)

    The search results page is a page every time, regardless of what’s pumped out in the search ;]

    L

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Find out if page or post in SERP?’ is closed to new replies.