Datafeedr Support Forums

Datafeedr Support Forums (http://www.datafeedr.com/forums/index.php)
-   Tips, Tricks & Tutorials (http://www.datafeedr.com/forums/forumdisplay.php?f=66)
-   -   Append Datafeedr Store Categories to Default WordPress Primary Menu (http://www.datafeedr.com/forums/showthread.php?t=3448)

Eric December 8th, 2010 08:41 PM

Append Datafeedr Store Categories to Default WordPress Primary Menu
 
This appends a Datafeedr category menu to the main navigation in the theme TwentyTen. Your theme must make a call to wp_nav_menu() in order for this to work.

First, open your theme's functions.php and add the following to the bottom of your functions.php file:

PHP Code:

// Add store categories to nav menu 
function dfr_menu_items($items$args) { 
    if (
$args->theme_location == 'primary') { 
        
$cats str_replace(array("<div>","</div>"), array("",""), datafeedr_tag('Category List?c=%ci')); 
        
$items $items $cats
    } 
    return 
$items

add_filter'wp_nav_menu_items''dfr_menu_items'10);
// add_filter( 'wp_list_pages', 'dfr_menu_items', 10, 2 ); 

In the Factory, create a new Custom View and give it the name "Category List". Make sure to select "Don't use layout for this view" in the View's properties menu.

Add a Category list module to the view area. Add the following code in the template area of your new view:
HTML Code:

[category.list id='dfparent' before='' after='']
<li>
  <a href="[category.link]" title="[category.name]">[category.name]</a>
  [category.list id='dfchild' before='<ul>' after='</ul>']
    <li>
      <a href="[category.link]" title="[category.name]">[category.name]</a>
      [category.repeat id='dfchild']
    </li>
  [/category.list]
</li>
[/category.list]

Update your store and now your menu should load the default primary links PLUS your store's categories.

This code shows how to add categories as a sub-menu to the "Store" menu link: http://www.datafeedr.com/forums/show...1913#post21913

For more information, see:
http://wpfirstaid.com/tag/wp_nav_menu/
http://www.wpbeginner.com/wp-themes/...rdpress-menus/

digitalcow January 9th, 2011 09:44 AM

Eric, followed the first post and nothing is showing up in my template. Re the 2nd post where should I enter str_replace(array("<div>","</div>"), array("",""), datafeedr_tag('Category List?c=%ci')); ? I assume echo str_replace(array("<div>","</div>"), array("",""), datafeedr_tag('Category List?c=%ci')); will go in the header of the template?

Eric January 9th, 2011 09:47 AM

Quote:

Originally Posted by ccgmark (Post 16267)
Eric, followed the first post and nothing is showing up in my template. Re the 2nd post where should I enter str_replace(array("<div>","</div>"), array("",""), datafeedr_tag('Category List?c=%ci')); ? I assume echo str_replace(array("<div>","</div>"), array("",""), datafeedr_tag('Category List?c=%ci')); will go in the header of the template?

Did you have a look at this thread: http://www.datafeedr.com/forums/showthread.php?t=3554

lbuilta59 January 23rd, 2011 09:02 PM

http://www.datafeedr.com/forums/showthread.php?t=3448
 
Quote:

Originally Posted by lbuilta59 (Post 17191)
Yes, it does. I'm going to try your suggestion shown for the twentyten theme. Fingers crossed!

I tried this and it didn't work.
Here is the error that appears at the top of my home page:

// Filter wp_nav_menu() to add additional links and other output function new_nav_menu_items($items) { $cats = str_replace(array("
","
"), array("",""), datafeedr_tag('Category List?c=%ci')); $items = $items . $cats; return $items; } add_filter( 'wp_list_pages', 'new_nav_menu_items' ); add_filter( 'wp_nav_menu_primary_items', 'new_nav_menu_items' );

I noticed that it changed the look of my product list items on the home page, though. Even after I delete the code from my functions.php page the front page (actually my entire store!) is still not going back to the correct layout.

Please help!

lbuilta59 January 23rd, 2011 09:19 PM

Store layout is ok now but I would appreciate some addtitional input on the category issue.
Thanks again.

Eric January 23rd, 2011 09:40 PM

Quote:

Originally Posted by lbuilta59 (Post 17192)
I tried this and it didn't work.
Here is the error that appears at the top of my home page:

// Filter wp_nav_menu() to add additional links and other output function new_nav_menu_items($items) { $cats = str_replace(array("
","
"), array("",""), datafeedr_tag('Category List?c=%ci')); $items = $items . $cats; return $items; } add_filter( 'wp_list_pages', 'new_nav_menu_items' ); add_filter( 'wp_nav_menu_primary_items', 'new_nav_menu_items' );

I noticed that it changed the look of my product list items on the home page, though. Even after I delete the code from my functions.php page the front page (actually my entire store!) is still not going back to the correct layout.

Please help!

The reason you were getting that error is because you pasted the PHP code into the file after the final closing php tag: ?>. You can't have PHP code which exists outside of opening <?php and closing ?> php tags.

As for integrating this into your theme, I'm not sure if it's possible. Your theme is calling it's own function to produce the menu UvumiDropdown(). Because your theme has written it's own code to generate the menu, I doubt that it is possible to hook into that function to append the menu with store categories. If your theme was using WordPress functions to generate the menu, it would not be a problem because WordPress provides a method to hook into those functions and modify their output. But most theme developers don't provide those types of hooks so when a theme developer writes their own function, there's usually no way to modify the output.

Eric

lbuilta59 January 23rd, 2011 10:14 PM

Thanks, Eric. I'm not great w/php yet but I am learning every day. And you just taught me something new :)

Do you think it is safe for me to try and edit the code? Or should I head over to the Atahualpa forums for advice?

Quote:

Originally Posted by Eric (Post 17194)
The reason you were getting that error is because you pasted the PHP code into the file after the final closing php tag: ?>. You can't have PHP code which exists outside of opening <?php and closing ?> php tags.

As for integrating this into your theme, I'm not sure if it's possible. Your theme is calling it's own function to produce the menu UvumiDropdown(). Because your theme has written it's own code to generate the menu, I doubt that it is possible to hook into that function to append the menu with store categories. If your theme was using WordPress functions to generate the menu, it would not be a problem because WordPress provides a method to hook into those functions and modify their output. But most theme developers don't provide those types of hooks so when a theme developer writes their own function, there's usually no way to modify the output.

Eric


Eric January 24th, 2011 08:28 AM

You could try creating a Primary Menu using the WP menu system. Then replacing the function Atahualpa uses to generate the menu with the WP native function wp_nav_menu(). You'll need to pass a few parameters into that function but maybe the Atahualpa devs could tell you how to do that.

grooves1200 February 17th, 2011 07:48 PM

I tried this and all i'm getting is a second version of "Store" on the top navigation. I did not see a closing ?> tag in the functions.php so i added one, but no luck. any ideas?

Eric February 17th, 2011 08:47 PM

You don't need a closing tag. What WP theme are you using? The instructions I posted are for the default WP theme TwentyTen. If you are using a theme that implements the menu system differently, you might need to modify this.

grooves1200 February 17th, 2011 08:48 PM

twentyten, right out of the box

Eric February 17th, 2011 08:56 PM

Have you created the new menu on the WP Menus page? It's hard to troubleshoot without knowing what you have and have not already done.

grooves1200 February 18th, 2011 02:34 PM

sorry, i didn't see any instructions on creating new menu on the menus page. still a newbie!

winsh March 14th, 2011 03:57 AM

Thanks for this code but could you tweak it so it only shows the store categories in the nav bar code? as I will put the blog categories in a widget.

Thanks

Eric March 14th, 2011 09:06 AM

You just need to get the name of the nav menu and substitute wp_nav_menu_primary_items with the new name. I'm not quite sure where you get that name from, though.

sovarn March 15th, 2011 06:56 PM

I have created a new menu called "products". But what is the correct add_filter to append the function to that particular menu?

Eric March 15th, 2011 07:16 PM

I'm not exactly sure... Are you sure it's not wp_nav_menu_products?

onlineshopper April 25th, 2011 07:38 PM

Hi Eric, it seems like this solution was for the older version of WP. Any solutions for the current version in hiding the "store" page. I have 'home' and 'store' linking to the same page (store front page). Thank you in advance for your help. Store id: 31337

Eric April 25th, 2011 08:14 PM

Quote:

Originally Posted by onlineshopper (Post 20190)
Hi Eric, it seems like this solution was for the older version of WP. Any solutions for the current version in hiding the "store" page. I have 'home' and 'store' linking to the same page (store front page). Thank you in advance for your help. Store id: 31337

I would just configure a custom WP Menu (Appearance > Menus). That's the easiest way to configure exactly what appears and does not appear in the menus on your site.

onlineshopper April 26th, 2011 05:27 PM

Thanks Eric. I started it that way. Then I added the code for drop down menu based on one of your instructions, but it wasn't working. So I changed the menu to not use the custom menu, and the drop down works, but I have two extra tabs for home and store. How can I have the drop down menu and custom WP menu? Thanks for your help!


All times are GMT -5. The time now is 10:46 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.