Datafeedr Support Forums  

Go Back   Datafeedr Support Forums > Current Version (V3) Forum > Tips, Tricks & Tutorials
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Important - The support forums are now in "read-only" mode as we transition to an alternative help desk solution. Feel free to contact us here with any of your questions or search the forums for an existing solution.
 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 8th, 2010, 08:41 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default 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/

Last edited by Eric : April 26th, 2011 at 06:43 PM. Reason: Updated function() for WP 3.1.1+
  #2  
Old January 9th, 2011, 09:44 AM
digitalcow digitalcow is offline
 
Join Date: Jun 2010
Posts: 494
Default

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?
  #3  
Old January 9th, 2011, 09:47 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Quote:
Originally Posted by ccgmark View Post
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
  #4  
Old January 23rd, 2011, 09:02 PM
lbuilta59 lbuilta59 is offline
 
Join Date: Jan 2011
Posts: 56
Default http://www.datafeedr.com/forums/showthread.php?t=3448

Quote:
Originally Posted by lbuilta59 View Post
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!

Last edited by lbuilta59 : January 23rd, 2011 at 09:07 PM.
  #5  
Old January 23rd, 2011, 09:19 PM
lbuilta59 lbuilta59 is offline
 
Join Date: Jan 2011
Posts: 56
Default

Store layout is ok now but I would appreciate some addtitional input on the category issue.
Thanks again.
  #6  
Old January 23rd, 2011, 09:40 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Quote:
Originally Posted by lbuilta59 View Post
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
  #7  
Old January 23rd, 2011, 10:14 PM
lbuilta59 lbuilta59 is offline
 
Join Date: Jan 2011
Posts: 56
Default

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 View Post
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

Last edited by lbuilta59 : January 23rd, 2011 at 10:17 PM.
  #8  
Old January 24th, 2011, 08:28 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

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.
  #9  
Old February 17th, 2011, 07:48 PM
grooves1200 grooves1200 is offline
 
Join Date: Feb 2011
Posts: 23
Default

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?
  #10  
Old February 17th, 2011, 08:47 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

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.
  #11  
Old February 17th, 2011, 08:48 PM
grooves1200 grooves1200 is offline
 
Join Date: Feb 2011
Posts: 23
Default

twentyten, right out of the box
  #12  
Old February 17th, 2011, 08:56 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

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.
  #13  
Old February 18th, 2011, 02:34 PM
grooves1200 grooves1200 is offline
 
Join Date: Feb 2011
Posts: 23
Default

sorry, i didn't see any instructions on creating new menu on the menus page. still a newbie!
  #14  
Old March 14th, 2011, 03:57 AM
winsh winsh is offline
 
Join Date: Jan 2011
Posts: 40
Default

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
  #15  
Old March 14th, 2011, 09:06 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

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.
  #16  
Old March 15th, 2011, 06:56 PM
sovarn sovarn is offline
 
Join Date: Mar 2011
Posts: 1
Default

I have created a new menu called "products". But what is the correct add_filter to append the function to that particular menu?
  #17  
Old March 15th, 2011, 07:16 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

I'm not exactly sure... Are you sure it's not wp_nav_menu_products?
  #18  
Old April 25th, 2011, 07:38 PM
onlineshopper onlineshopper is offline
 
Join Date: Mar 2011
Posts: 13
Default

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
  #19  
Old April 25th, 2011, 08:14 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Quote:
Originally Posted by onlineshopper View Post
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.
  #20  
Old April 26th, 2011, 05:27 PM
onlineshopper onlineshopper is offline
 
Join Date: Mar 2011
Posts: 13
Default

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!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:06 AM.


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