0

Let’s say I have one post with tittle "Dummy one" and that post is filed under "Category one" and i have other post eg : "dummy two, dummy tree, etc" and category two, category three etc.

and now I create other post with title "helper for category one" how to display permalink to "helper for category one" in all post with "category one"

I want to put it under the_content(); in single.php.

Let’s say my single.php is like this

if( have_post()):
while( blah blah ):
the_content();
endwhile;
endif;

i want to like this.

if():
while():
the_content();
if(category == "category one"):
display_helper_for_category_one
else:
display_nothink
endif;
endwhile;
endif;

How can I do that?

2 Answers 2

0

yes you can do that. You can use get_category_link for it.


if():
while():
the_content();
if(category == "category one"){
   // Get the ID of a given category
    $category_id = get_cat_ID( 'helper for category one' ); //get_cat_ID('category_name');

    // Get the URL of this category
    $category_link = get_category_link( $category_id );

    // Print category link here
}
else{
   display_nothink
}
endif;
endwhile;
endif;

You can also use action/filter if you dont have direct access to single.php file

0

In WordPress post loop, you can use the following function:

if ( in_category( 'pachyderms' )) {
// display_helper_for_category_one
} else {
// display_nothink
}

Reference: http://codex.wordpress.org/Function_Reference/in_category

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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