开发者

Post thats in Two Categories, only want to display name for one

开发者 https://www.devze.com 2023-02-06 18:39 出处:网络
In my Wordpress site I\'ve created, I\'m having issues hiding开发者_开发百科 or not displaying one of the category titles I set up. I\'ll try to explain better.

In my Wordpress site I've created, I'm having issues hiding开发者_开发百科 or not displaying one of the category titles I set up. I'll try to explain better.

Wordpress Admin Side

I have a post that is in two categories, a "Work" & "Front_Page"

Main Page / index.php

On my main index page, I have 3 features below the header image. One of those features is a "Featured Project". This is how I'm starting the loop...

    <? $frontpost = get_posts("category_name=front_page&numberposts=1");?>

Single Project Page

Now on this page, the visual layout is

Category Name

Which is called <h2 class="single_category"><?=$cat[0]->name;?></h2>

Project Title

Large Header Image

Project Desription

THE PROBLEM!!!

For whichever post I put in "Front_Page", it displays that in the Category Name. I want it to default to the main category.

Is there a way to basically say "if post is in "front_page" category, don't display "front_page" category as name?


You could restrict whether to display the category name or not using in_category() .

<?php
   //if post is NOT in category 'front_page' display cat name
   if(!in_category('front_page')){?>
      <h2 class="single_category"><?=$cat[0]->name;?></h2>
<?php } ?>

You can place that in your single.php (or loop.php, depending on your theme) file in the area where you display the cat name.

I hope that helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消