Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Getting the "href" category page on a filtering menu WordPress

  • SOLVED

Hello,

I'm using a theme called "FolioGrid" where there is a wp_dropdown_categories($cats); ? filtering menu.

I want to change the dropdown menu to a simple list "ul" with "li" display set has "list-item".

The menu has 3 links.

Here is the code of the original menu :

<div class="categories">

<?php

$cats = array('show_option_none' => __('Select Category', 'foliogridpro'));
wp_dropdown_categories($cats); ?>

</div>


I wrote this and manage to have the menu display has list-item :

<div class="categories">

<?php

$cats = array('show_option_none' => __('Select Category', 'foliogridpro'));

$categories=get_categories($args);
foreach($categories as $category) { ?>
<li><a href="#" data-filter=".<?php echo $category->category_nicename; ?>"><?php echo $category->name; ?></a></li>
<?php } ?>
</ul>

</div>


But I miss the link to the categories.

Here is the answer of the guy from support theme :

<blockquote>I imagine it won't filter as you don't have the 'href' set to go to that category page. It doesn't do the filtering with AJAX on this theme if that's what you are expecting? It goes direct to the category page.</blockquote>

Can anyone help me to manage to get the 'href' set to go to that category page.
Thanks a lot.

Answers (4)

2012-05-29

Arnav Joy answers:

use this
<li><a href="<?php echo get_category_link($category->term_id; )?>" data-filter="<?php echo $category->category_nicename; ?>"><?php echo $category->name; ?></a></li>


Arnav Joy comments:

here is the full code

<div class="categories">



<?php



$cats = array('show_option_none' => __('Select Category', 'foliogridpro'));



$categories=get_categories($args);

foreach($categories as $category) { ?>

<li><a href="<?php echo get_category_link( $category->term_id )?>" data-filter="<?php echo $category->category_nicename; ?>"><?php echo $category->name; ?></a></li>

<?php } ?>

</ul>



</div>


guillaume guillaume comments:

Thank you Arnav.
It's working.

2012-05-29

rizaljohn answers:

You can try this:
<?php
// Get the URL of this category
$category_link = get_category_link( $category_id );
?>

<!-- Print a link to this category -->
<a href="<?php echo esc_url( $category_link ); ?>" title="Category Name">Category Name</a>

2012-05-29

Jeffri Hong answers:

I think you need get_category_link to get the link.

Try this

<li><a href="<?php echo get_category_link($category->term_id) ?>" data-filter=".<?php echo $category->category_nicename; ?>"><?php echo $category->name; ?></a></li>


-------------------------------

Late by a minute. Please refer to answer above me instead.. :)

2012-05-29

Ivaylo Draganov answers:

Hello,

There's no need to write custom functions - use [[LINK href="http://codex.wordpress.org/Template_Tags/wp_list_categories"]]wp_list_categories()[[/LINK]] instead.


<div class="categories">
<?php
$cats = array('show_option_none' => __('Select Category', 'foliogridpro'));
wp_dropdown_categories($cats); ?>
</div>