0

I'm using a custom theme from ThemeForest and I'm trying to get the custom post php to check and see if the post is on a category or single post. If it's on category, use <h2> for the title (for SEO purposes), if it's on the post's individual/single page, then use <h1>.

Here is the public function that exists:

public function title() {
  echo '<h2 class="post_title">';
  echo '<a href="';
  the_permalink();
  echo '" data-disqus-identifier="';
  the_ID();
  echo '">';
  the_title();
  echo '</a></h2>';
}

I tried this, and no luck:

public function title() {
    global $post;
  if is_category() {
    echo '<h2 class="post_title">';
    } else {
    echo '<h1 class="post_title">';
};
  echo '<a href="';
  the_permalink();
  echo '" data-disqus-identifier="';
  the_ID();
  echo '">';
  the_title();
  if is_category() {
      echo '</a></h2>';
    } else {
      echo '</a></h1>';
};
}

Not sure what I'd need to do. I can get the global $post; but I'm not sure that will help.

Thanks for the hack help! :D

UPDATE: here is the code of the entire pt_post.php

/******************************************************************************/
/*----------------------------------------------------------------------------*/
/* BLOG - FEATURED IMAGE
/*----------------------------------------------------------------------------*/
/******************************************************************************/
    public function printBlogFeaturedImage() {
        global $post;

        $isVideo = ffWP::getWp('featured isvideo');
        if( $isVideo ){
            $videoLink = ffWP::getWp('featured video-link');
            $videoLink = trim($videoLink);
            if( empty($videoLink) ){
                $isVideo = 0;
            }
        }

        if( $isVideo ){
            $this->_printBlogFeaturedImageVideo($videoLink);
        }else{
            $gallery = ffGalleryCollection::getGallery( $post->ID );
            $this->featuredImage($gallery);
        }
    }

/*----------------------------------------------------------------------------*/
/* BLOG - VIDEO
/*----------------------------------------------------------------------------*/
    protected function _printBlogFeaturedImageVideo( $videoLink ) {
        $mediaInserter = new ffMediaInserter();
        $videoIframeSrc = $mediaInserter->getIframeSource( $videoLink );

      echo  '<div class="video_container">
                            <div class="video_wrapper">
                                <iframe class="video" src="'.$videoIframeSrc.'" alt="" /></iframe>
                            </div>
                        </div>';
    }
/*----------------------------------------------------------------------------*/
/* TITLE
/*----------------------------------------------------------------------------*/
    public function title() {
      echo '<h2 class="post_title">';
      echo '<a href="';
      the_permalink();
      echo '" data-disqus-identifier="';
      the_ID();
      echo '">';
      the_title();
      echo '</a></h2>';
    }
}

// MY FAILED ATTEMPT BELOW
/*  public function title() {
        global $post;
      if is_category() {
        echo '<h2 class="post_title">';
        } else {
        echo '<h1 class="post_title">';
    };
      echo '<a href="';
      the_permalink();
      echo '" data-disqus-identifier="';
      the_ID();
      echo '">';
      the_title();
      if is_category() {
          echo '</a></h2>';
        } else {
          echo '</a></h1>';
    };
    }
}*/
  • The code you posted looks to me like it should work just fine. It is not clear, however, how the title() function is being called. Can you shed some light on that? From where in your template is it being called from? – Will Dec 30 '13 at 6:54
  • hey @WilltheWebMechanic, thanks for the help! title is called within pt_post.php which extends htmlPTPrinter. I'll post the code up above. Then that is grabbed in the post template within the loop calling a custom templater requirement: ffTemplater::requireLoopItemPost(); – tigre Dec 30 '13 at 7:00
  • That doesn't help me much - maybe someone who is familiar with this particular theme might have some insight. However, I'm just going to take a guess here that since the disqus identifier is being echoed out, that this particular function is only being called on single post pages...I could be wrong. What is the result of your failed attempt? Do you get h1 tags on single posts? – Will Dec 30 '13 at 7:11
  • I get the glory of the white screen of death. :) Both the category template and single post template call this requireLoopItemPost from the templater.php. I guess the possible solution is to duplicate the action and do the if_else inside the template file within the loop. :-/ – tigre Dec 30 '13 at 7:27
0

aha...white screen of death. I don't know how I missed it. Your if statement lacks parenthesis.

Try this:

public function title() {
  if ( is_category() ) {
    echo '<h2 class="post_title">';
    } else {
    echo '<h1 class="post_title">';
};
  echo '<a href="';
  the_permalink();
  echo '" data-disqus-identifier="';
  the_ID();
  echo '">';
  the_title();
  if ( is_category() ) {
      echo '</a></h2>';
    } else {
      echo '</a></h1>';
};
}

stackexchange needs syntax highlighting :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.