Okay
  Public Ticket #562972
Displaying Portfolio Category
Closed

Comments

  • Jordan started the conversation

    I'm trying to add a category listing to the header in single-portfolio.php here:

    <?php nectar_page_header($post->ID);
    if(empty($bg) && empty($bg_color)) {?>
    <div class="row project-title">
    <div class="container">
    <div class="title-wrap">
    <div class="col span_12 section-title <?php if(empty($options['portfolio_social']) || $options['portfolio_social'] == 0 || empty($options['portfolio_date']) || $options['portfolio_date'] == 0 ) echo 'no-date'?>">

    <h1><?php the_title(); ?></h1>

    <?php
    $options = get_option('salient');

    –––––––––––––––

    I'm simply trying to add - <?php the_category(', '); ?> next to the title in the h1 tag, but it's not working. Could you suggest something else that will print the category names? Thanks in advance.


  •  8,990
    Tahir replied
    Try adding like this
    <h1><?php the_title(); the_category(\', \'); ?></h1>

    Thanks


    ThemeNectar Support Team 

  • Jordan replied

    That didn\'t seem to work. It\'s still outputting the title just fine, but it\'s not showing the category. And I\'d still like the category to be seperated by a dash.

  • jeroen replied

    Hi, This should work for a dash: <?php the_category(\'- \'); ?>

    Also, try to put it outside/after the H1.

    You may try get_the_category() as well.

    What category name should it display? Do you have an online example?

  • Jordan replied

    Thanks for the reply! Unfortunately those solutions didn\'t work either. I\'m developing on a private server, but here\'s an example of the same thing working on another site.

    http://www.digitalbase.com/_2015/portfolio/zimmerman-honda/

    According to the code, it should say, \"Zimmerman Honda - HOME\".

    <h1><?php the_title(); ?> - <?php the_category(); ?></h1>

    I\'ve tried it inside and out of the H1 with no change. I\'ve also tried the variation you sent. I just don\'t understand why the title reference works, but not the category. Any ideas?

  • jeroen replied

    (edited)

  • jeroen replied

    The_category shows the category of a post. I think you\'re looking for something else, like the category of the portfolio filter, which is something different. So with your code, it tries to show a category which probably isn\'t there.

  • Jordan replied

    Ah, that makes sense, I didn\'t realize they were different. Is there a reference I could use for the portfolio category? I don\'t know if I formatted it right, but I tried the following and got nothing:

    	<h1><?php the_title(); ?> - <?php $cats = get_the_category(); $cat_name = $cats[0]->name; ?></h1>
  • Jordan replied

    Oh well, thanks for your help.