creariz
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: wp_enqueue_scripts for stylesheets not workingThank you James. That was the actual solution to the problem. I really didn′t need the condition, cause wp_enqueue_scripts doesn′t run on admin pages or the login. Everything is working now.
Forum: Themes and Templates
In reply to: WP Nav Menu Dissapears in Category Pages!Thank you esmi and jian118. I just solved the problem thanks to you guys.
This is the code:
functions.php
function getMainMenu($menulocation){ $locations = get_nav_menu_locations(); $menuItems = wp_get_nav_menu_items( $locations[ $menulocation ] ); if(empty($menuItems)) return false; else{ wp_nav_menu(array('theme_location' => $menulocation)); return true; } }
template file
if(!getMainMenu('primary')){ $backup = $wp_query; $wp_query = NULL; $wp_query = new WP_Query(array('post_type' => 'post')); getMainMenu('primary'); $wp_query = $backup; }
Forum: Themes and Templates
In reply to: WP Nav Menu Dissapears in Category Pages!Hi, I’m having the same problem for a few weeks now. I’m glad I found this blog, because I was totally lost. My primary menu shows perfect with page.php and single.php but it doesn’t work with category.php
I’m trying to implement jian118 solution but I can’t image how am I gonna make getMainMenu()? cause wp_nav_menu() prints directly and I can’t get a return value to evaluate true or false. I know that probably I have the solution in front of me but I can’t see it.
I have issues finding the solution to this problem because I really don’t know why it is happening.
I found this post by Ronald Huereca: https://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops.
It explains why pagination doesn’t work on category.php. He says that next_posts_link and previous_posts_link functions, as well as several others, make use of a global variable called $wp_query. This variable is actually an instance of the WP_Query object. However, when we create our own instantiation of WP_Query, we don’t have this global variable $wp_query, which is why paging will not work.
I think that could be a good explanation if only I could understand how $wp_query works, when it is instantiated, and why is it that when the category.php calls the header.php the menu doesn’t work, or wp_query is not ready.
I posted this commentary just to ask for some help for make getMainMenu(), sorry if just made a lot of questions. Thanks.