0

I have this code:

<div class="widget-title"><h2><?php echo esc_attr(of_get_option('carousel_post_title'));?></h2></div>

So in my home-page.php i GET the categories, how it is possible while i get the categories, to get also the link of the categories in self??

my page php code is :

<div class="carousel_post_home_wrapper">
<div class="row carousel_post_home">
  <div class="twelve columns carousel_header_wrapper">
 <div class="widget-title"><h2><?php echo esc_attr(of_get_option('carousel_post_title'));?></h2></div> 

 <div class="owl_carousel carousel_header">


       <?php
  $category_carousel_post="";
  $number_of_carousel= of_get_option('number_carousel');
  $category_carousel= of_get_option('carousel_post');
  if (of_get_option('number_offset_carousel_post')){$number_offset_carousel_post = of_get_option('number_offset_carousel_post');}else{$number_offset_carousel_post = 0;}

  if(!empty($category_carousel)) {

  foreach($category_carousel as $key=>$value) { if($value == 1) { $category_carousel_post[] = $key; } } 
  }


  $post_array_carousel = array(
            'showposts' => $number_of_carousel,
            'category__in' => $category_carousel_post,
      'ignore_sticky_posts' => 1,
      'offset' => $number_offset_carousel_post
        );  
        $jellywp_widget_carousel = new WP_Query($post_array_carousel);
    $i=0;
     while ($jellywp_widget_carousel->have_posts()) {
            $jellywp_widget_carousel->the_post();
      $i++;
      $post_id = get_the_ID();
      //get all post categories
            $categories = get_the_category(get_the_ID());

What i mean is every time i have the category title i want also this title have a link and go to mypage.com/category/nameofthecategory

Sorry about my English, if you need further explanation tell me please..

0

Well, WordPress has some integrated functions for that. Two of those would be get_category_by_slug (Codex link) or get_category_link (Codex link).

I am not sure what of_get_option() returns, but those two might help you.

3
  • Forgot to mention that i tried these on WordPress codex.I Didn't worked it out how to place my php so any time the category has a link also, so in click, visitor can see all the category.php //
    – StefanoWP
    Apr 30 '15 at 10:48
  • The theme is using a page builder, so you manage what category will be visible in the home-page.php and pull any time what category you "tick", so, the problem is, i want to add a code, that will pull the link of the category together with the title of the category(probably title is already get) the question is: that how i will link that title to the category ant time, is it function should i edit any code in my functions.php, should i code my home-pahe.php ???I think is too complicated :(
    – StefanoWP
    Apr 30 '15 at 11:01
  • Well, it´s surely possible. But you need to have a good knowledge of how the theme works, where and how those links are generated, if you can overwrite those functions etc. I am sorry, but we need more information to help you on this. Like: "I got this function to output category links and I tried this and that code and it won´t work."
    – flomei
    Apr 30 '15 at 11:11

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.