WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Coding problem (4 posts)

  1. rwwood
    Member
    Posted 2 years ago #

    Can anyone help me fix this chunk of code that I have in my single.php file? I'm no php guru, but I can't see why it's causing a blank page to be returned.

    $current_category = single_cat_title("", false);
      $category = get_category($current_category);
      $cat_slug = $category->slug;
    
      if ($cat_slug == "wolves-in-sheeps-clothing" || $cat_slug == "fruit-that-remains") {
        $my_post_type = "chapter";
        $my_category_type = "this booklet";
      }
      else {
        $my_post_type = "post";
        $my_category_type = "this category";
    ?>
            <div id="post-navigation">
    					<div class="nav-previous"><?php previous_post_link('%link', 'Previous ' . $my_post_type . ' in ' .  $my_category_type, TRUE); ?></div>
    					<div class="nav-next"><?php next_post_link('%link', 'Next ' . $my_post_type . ' in ' .  $my_category_type, TRUE); ?></div>
    				</div>
  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    get_category() uses the category ID;

    http://codex.wordpress.org/Function_Reference/get_category

    single_cat_title() only works in category archives, not within the loop:

    http://codex.wordpress.org/Function_Reference/single_cat_title

    try to change the first three lines to:

    $current_cats = get_the_category();
    $current_category = $current_cats[0]->term_id;
      $category = get_category($current_category);
      $cat_slug = $category->slug;

    if this doew not help, paste the full code of single.php into a http://pastebin.com/ and post the link to it here; HOWTO

  3. rwwood
    Member
    Posted 2 years ago #

    That didn't work, so here's the link to the file on pastebin.com

    link on pastebin

  4. rwwood
    Member
    Posted 2 years ago #

    It turned out to be a missing curly bracket. Duh.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.