I'm using a theme called hotheme(dot co) which seems not working properly. I added some links to my menu in the backend and linked it to "main menu" but on the frontend the inspector shows an empty
Here's the code for the menu from the header.php
`
global $wpdb;
$tablename = $wpdb->prefix.'terms'; // use always table prefix
// language support
switch ($lang){
case '':
case '1':
$menu_name = 'default';
break;
case '2':
$menu_name = 'secondary';
break;
}
$menu_id = $wpdb->get_results(
"
SELECT term_id
FROM ".$tablename."
WHERE name= '".$menu_name."'
"
);
// Empty check
if($menu_id != null){
// results in array
foreach($menu_id as $menu):
$menu_id = $menu->term_id;
endforeach;
$items = wp_get_nav_menu_items( $menu_id );
$numItems = count($items);
$i = 0;
foreach($items as $item)
{
if(++$i === $numItems) {
echo "<li class='reservation-btn custom-color-btn-back'><a href='".$item->url.$lang_link.$lang."'>".$item->title."<br /><span class='grey'>".$item->description."</span></a></li>";
$_SESSION['reservation_url'] = $item->url;
} else {
echo "<li><a href='".$item->url.$lang_link.$lang."'>".$item->title."<br /><span class='grey'>".$item->description."</span></a></li>";
}
}
} // end: empty check
?>`
Could it be possile, that the code is deprecated?
Any help would be great! Thanks
That seems like a lot of unneeded code. I am going to give you some code (alters slightly) that I wrote for a theme framework that I am working on. You can add it to the theme and see if a menu shows up or not.
Add to functions.php
function ao_register_menus() {
register_nav_menu( 'primary', 'Primary Navigation');
}
add_action( 'init', 'ao_register_menus' );
function ao_primary_nav() {
echo '<nav class="primary-navigation">';
wp_nav_menu(array(
'theme-location' => 'primary',
'container_class' => 'primary-nav-container',
'menu_class' => 'primary-nav',
));
echo '</nav>';
}
add_action('ao-primary-nav', 'ao_primary_nav');
Then after that, you should be able to add the following to replace all of the code that you showed from header.php with this:
do_action('ao-primary-nav');
Warning: Doing this will destroy the styles attached to your theme's navigation. So don't erase the code the is already there, but instead simply use this to check to see if the navigation functionality is still existent. From here we can see if the theme overall is outdated or if there are bigger underlying issues. This is not a permanent solution. However, if this works and you see A NAVIGATION then it is a good sign that we can dig into the theme further to see what exactly is going on.
You could also always check the changelog of the theme to see when it was last updated and that could be a good sign of whether or not you should use it.
Menu is working fine in Hotheme. You have to read the documentation provided in http://www.hotheme.co/page-documentation.php#doc-3-1. In Menu topic they have mentioned, name the menu as "default".
Related
I have an issue with one of the websites I work on where the "edit_in_content" location setting for Elementor popups is set to FALSE for all popups, and it is preventing the admin from going to the Elementor editor.
This issue presents itself as the common "the_content not found" error message, however, debugging leads to the location settings for popups being the issue. The problem is in the builder_wrapper method of \ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager, which is in /elementor-pro/modules/theme-builder/classes/locations-manager.php.
public function builder_wrapper( $content ) {
$post_id = get_the_ID();
if ( $post_id ) {
$document = Module::instance()->get_document( $post_id );
if ( $document ) {
$document_location = $document->get_location();
$location_settings = $this->get_location( $document_location );
/**
* Custom Modification Begin
* ------------------------------------
*/
if( $document_location == 'popup' )
return $content;
/**
* Custom Modification End
* ------------------------------------
*/
// If is a `content` document or the theme is not support the document location (header/footer and etc.).
if ( $location_settings && ! $location_settings['edit_in_content'] ) {
$content = '<div class="elementor-theme-builder-content-area">' . __( 'Content Area', 'elementor-pro' ) . '</div>';
}
}
}
return $content;
}
I'm aware that this is a plugin hack, and not recommended, but I have found no other way to handle the issue.
I'm not sure why edit_in_content is FALSE for all popups.
I've found no way to ensure that edit_in_content is TRUE so that the admin can work with popups.
To be fair, I should disclose that the theme is custom, but rather minimal. When switching to twentytwenty the issue goes away. ALL plugins have been disabled during testing, and it seems that the popup location setting is somehow being affected by the custom theme.
I've found nothing in twentytwenty that references elementor in any way.
I've been through Elementor's docs related to the_content issues, and nothing noted there leads to success. Ref: https://docs.elementor.com/article/56-content-area-not-found
So, I'm hoping somebody will be able to shed some light on this issue. What can I do so I don't have to hack the plugin?
I'm posting an answer because I found something that I could do to not hack the plugin, although I'm still curious to why it needs to be done. I basically just add a hook/action that reprocesses the popup location after it was initially registered. This could go in the theme's functions.php file:
function fixElementorPopupLocation( $that )
{
$loc = $that->get_location('popup');
if( ! $loc['edit_in_content'] )
{
$args = [
'label' => $loc['label'],
'multiple' => $loc['multiple'],
'public' => $loc['public'],
'edit_in_content' => TRUE,
'hook' => $loc['hook'],
];
$that->register_location('popup', $args);
}
}
add_action(
'elementor/theme/register_locations',
'fixElementorPopupLocation',
93062220
);
If anyone could tell me why I need to do this, and why I don't need this in the twentytwenty theme, I'd be glad to accept that as an answer, provided I can use the advice to "fix" my theme.
I wish to include a button on the website so that users can toggle out of stock items on and off.
By default, I want the out of stock items to be false. When the user browses around I need the setting he applies to be consistent. Is this possible?
This is what I have till now:
/*
* ADDING A SIMPLE BUTTON TO SHOW OR HIDE SOLD PRODUCTS
* source: https://www.offshorly.com/news/woocommerce-show-hide-sold-products-toggle/
*/
function hide_sold_products_param() {
global $wp;
$wp->add_query_var('hide_sold_products');
}
add_filter('init', 'hide_sold_products_param');
add_action('pre_get_posts', 'hide_sold_products_query', 10);
function hide_sold_products_query($query){
if($query->get('hide_sold_products') == 'true'){
$query->set('meta_query', array(
array(
'key' => '_stock',
'value' => '0',
'compare' => '>'
)
));
}
}
I also have a button on the sidebar to toggle the status.
Currently, it is not consistent
The default is not hiding out of stock items
Any help is greatly appreciated.
I looked more into this and came up with a solution, it is not ideal but it does work the way that I wanted it too. I think your biggest issue is you need to store the toggle on/off into the users session so that it gets saved as they navigate it. In header.php I added:
if (isset($_GET['hide_sold_products']) && $_GET['hide_sold_products'] === 'true') {
WC()->session->set( 'hide_sold_products', 1 );
}
if (isset($_GET['hide_sold_products']) && $_GET['hide_sold_products'] === 'false') {
WC()->session->set( 'hide_sold_products', 0 );
}
This stores the users hide/show value from the ?hide_sold_products= url variable.
Again the following is not ideal but I'll share, also added this to header.php
<?php
if($wp->request == 'store'){
$url = $wp->request;
} else {
$url = strstr($wp->request, '/', true);
}
if(!isset($_GET['hide_sold_products']) && $url == 'store'){
$currentUrl = "http://" . $_SERVER['HTTP_HOST'];
$hide_sold_products = WC()->session->get( 'hide_sold_products' );
if($hide_sold_products == 1){
$hide_sold_products_text = 'true';
} else {
$hide_sold_products_text = 'false';
}
?>
<script>
window.location = "<?php echo $currentUrl . '/' . $wp->request . '/?hide_sold_products=' . $hide_sold_products_text; ?>";
</script>
<?php } ?>
This checks to see if the user is trying to access the /store/ url in woocommerce and then will redirect them and add ?hide_sold_products= with the true/false from the session value then the url calls functions.php script. Also on your toggle button/text on the front end the show toggle needs to have this appended to it: ?hide_sold_products=false
Other than the JS redirection this works well for me. I tried the wp_redirect() but ran into the headers already sent issue since the code is in the header.php
I'm using the Types Wordpress plugin to enable custom fields. The plugin allows you to rearrange the order of the images in the admin page editor. Here's my code in my single.php to display multiple images in the custom field and have a link to itself to also use Fancybox:
<?php
$mykey_values_img = get_post_custom_values('wpcf-image');
if ($mykey_values_img != null) {
foreach ( $mykey_values_img as $key => $value ) {
?>
<img src="<?php echo $value; ?>" />
<?php
} //foreach
} //if
?>
Problem:
Right now this code works perfectly on my local copy running on MAMP. However, when I put it online hosted on iPage, the images are out of order. I don't know what's causing this discrepancy. When I use the shortcode from Types to display the images instead of the php above they are in order, but I don't have the option of using Fancybox. I was also wondering if there is a better way to display an image from Wordpress that will insert the alt tag for the image.
I just encountered this problem too, and your first answer led me to a tighter solution.
I also used types_render_field(), but if you include a 'raw' parameter, you can avoid the string manipulation.
$images_raw = types_render_field('image', array('raw'=>'true','separator'=>';'));
$images = explode(';', $images_raw);
foreach ($images as $link) {
echo '' . $link . '">"';
}
Then, if you're nasty, you can get the ID of the attachment from its SRC. Using that ID, you can get all the info you need about that attachment, like a caption, or whatnot.
I figured out a work around to get it working. Its not ideal but it works.
The Types plugin came with its own php function to display the custom field called types_render_field. It displayed my images in order. To get fancybox working I had to do sort of a hack on the string. Here's the code:
$images = ( types_render_field( "image", array( 'size' => 'full', 'alt' => get_the_title(), 'title' => get_the_title() ) ) );
$imgArray = explode(">", $images);
foreach ( $imgArray as $value ) {
$pos1 = strpos($value, 'src="', 0)+5;
$pos2 = strpos($value, '" ', $pos1);
$link = substr($value, $pos1, $pos2 - $pos1);
echo ''.$value.">";
}
(This post has been submitted on the Yootheme forums but I don't have as much confidence in a solution so I thought I'd post it here too.)
I'm using the Nano theme from Yoothemes and its working great for 90% of my site. http://dofekit.org However I've just installed the bbPress forum plugin (not on the live site, but a local version) and I have created 2 'forums'. The forum index page and all sub-pages seem to be inserted into a standard Nano page template. This is not suitable for the forum as it includes the page meta information and also I see no way of turning off 'sidebar-a' for the forums as my screenshot demonstrates.
http://dl.dropbox.com/u/240752/forums.jpg
Is there a way of creating a separate template for the forum post type within the yoothemes framework? ( I know its kind of proprietary but I can but ask)
Thanks.
UPDATE:
I'm part of the way there. I've manged to make separate templates for my forum post types like so, but I still need to get the custom post types to be acknowledged in the widget settings.
I've added the custom post types in warp/systems/wordpress3.0/layouts/content.php
if (is_home()) {
$content = 'index';
} elseif (is_page()) {
$content = 'page';
} elseif (is_attachment()) {
$content = 'attachment';
} elseif ((is_single()) && (get_post_type() == 'forum')) {
$content = 'forum-single';
}elseif ((is_single()) && (get_post_type() == 'topic')) {
$content = 'topic-single';
} elseif (is_single()) {
$content = 'single';
} elseif (is_search()) {
$content = 'search';
}elseif ((is_archive()) && (get_post_type() == 'forum')) {
$content = 'forum-archive';
} elseif (is_archive() && is_author()) {
$content = 'author';
} elseif (is_archive()) {
$content = 'archive';
} elseif (is_404()) {
$content = '404';
}
I've also added these custom post types into
warp/systems/wordpress3.0/config/layouts/fields/profile.php
in an effort to get them to appear in the dropdown lists on each widget. (I want to be able to toggle widgets on these new custom templates.)
$defaults = array(
'home' => 'Home',
'archive' => 'Archive',
'search' => 'Search',
'single' => 'Single',
'page' => 'Pages',
'forum-archive' => 'Forum List',
'forum-single' => 'Forum Single',
'topic-single' => 'Topic Single'
);
Can anyone please help? I think I'm almost there with this.
You should be able to handle this using a WordPress Template for your custom post type for single post display.
For example if your custom post type is called "product" create a template called single-product.php e.g. single-{post_type}.php
This solution should work irrespective of Yoothemes framework, Let me know if that works!
i'm not shure if my answer can help you but...
My code add the Custom Taxonomy categories to the widget position...
I edit the file warp/systems/wordpress/config/layouts/fields/style.php
and I add this lines for each custom taxonomy =)
// set Eventos cate
if ($categories = get_categories(array('hide_empty' => 0, 'name' => 'select_name', 'post_type' => 'event', 'taxonomy' => 'event-category'))) {
$options[] = '<optgroup label="Eventos | Categorias">';
foreach ($categories as $category) {
$val = 'cat-'.$category->cat_ID;
$attributes = in_array($val, $selected) ? array('value' => $val, 'selected' => 'selected') : array('value' => $val);
$options[] = sprintf('<option %s />%s</option>', $control->attributes($attributes), $category->cat_name);
}
$options[] = '</optgroup>';
}
Here... my postype is "event" and my taxonomy is "event-category" in the list of the widget position now you can see all the Categories or Terms of the Taxonomy and y label it with "Eventos | Categorias" for a better identification.
Ok this is only one part of the code and maybe you can take this like a point to start. Now i just can display and list this terms but still nok working :(
so... tnks for the comments and sorry for my english :P
I'm trying to deal with Wordpress 3.0. It's rather cool thing but I can't get on with one problem. For example, I have such menu tree. Menu tree is constructed from pages.
Home
news
video
audio
Blog
About author
Favourite colors
red
blue
green
My car
wheels
tires
The Idea is:
main menu consists of root elements: home, blog, my car
On the left side I would like to display children elements of current active root element.
For exammple if person is on the "home" page, on the left part he should see:
news
video
audio
If user is on the "Blog" page, he should see:
About author
Favourite colors
red
blue
green
I can't find an API to do that. Can you sugest me please where can I find it?
UPD:
#Jason McCreary
I've seen I've seen wp_list_pages() and tried it. I din't get how can I use it:
Please, see my template for a page:
<?php
/*
Template Name: page_news
* #package WordPress
* #subpackage Twenty_Ten
* #since Twenty Ten 1.0
*/
get_header(); ?>
<h1>page_news</h1>
<h1>Children menu:</h1>
<?php wp_list_pages('echo=0&child_of=8&title_li='); ?>
<div id="container">
<div id="content" role="main">
<?php
/** Get category id by name*/
//$catId = get_category_by_slug('news')->term_id;
query_posts('category_name=news');
get_template_part( 'loop', 'page' );
?>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
See this line of code:
<?php wp_list_pages('echo=0&child_of=8&title_li='); ?>
I do have the page with id=8 (I see it in URL). Page with id=8 has several children.
I want to print them, but they are not printed. The output of the function wp_list_pages() is nothing.
I don't know why... :(
You can write a filter_hook to accomplish this.
My method: create an additional start_in argument for wp_nav_menu using my custom hook:
# in functions.php add hook & hook function
add_filter("wp_nav_menu_objects",'my_wp_nav_menu_objects_start_in',10,2);
# filter_hook function to react on start_in argument
function my_wp_nav_menu_objects_start_in( $sorted_menu_items, $args ) {
if(isset($args->start_in)) {
$menu_item_parents = array();
foreach( $sorted_menu_items as $key => $item ) {
// init menu_item_parents
if( $item->object_id == (int)$args->start_in ) $menu_item_parents[] = $item->ID;
if( in_array($item->menu_item_parent, $menu_item_parents) ) {
// part of sub-tree: keep!
$menu_item_parents[] = $item->ID;
} else {
// not part of sub-tree: away with it!
unset($sorted_menu_items[$key]);
}
}
return $sorted_menu_items;
} else {
return $sorted_menu_items;
}
}
Next, in your template you just call wp_nav_menu with the additional start_in argument containing the ID of the page you want the children off:
wp_nav_menu( array(
'theme_location' => '<name of your menu>',
'start_in' => $ID_of_page,
'container' => false,
'items_wrap' => '%3$s'
) );
I wrote this to print sub-navs of the pages you may be on. If you want to print out the sub-navigation for each of the pages, get the page parent instead of getting the ID. There would be more involved than that, but it's a start.
$menu = wp_get_nav_menu_items( 'Primary Menu' );
$post_ID = get_the_ID();
echo "<ul id='sub-nav'>";
foreach ($menu as $item) {
if ($post_ID == $item->object_id) { $menu_parent = $item->ID; }
if (isset($menu_parent) && $item->menu_item_parent == $menu_parent) {
echo "<li><a href='" . $item->url . "'>". $item->title . "</a></li>";
}
}
echo "</ul>";`
Check out wp_list_pages(). It is useful for providing child navigation in the sidebar.
mac joost's answer is great, but I would add that if you want the parent item to print, then you shouldn't unset the parent, so line 18 needs to be adjusted accordingly:
if($item->object_id != (int)$args->start_in) { unset($sorted_menu_items[$key]); }
have you seen wp_list_pages?
http://codex.wordpress.org/Function_Reference/wp_list_pages
look closer on child_of attribute
You can use Breadcrumb navxt plugin. It does exactly what you are looking for and its really great.
Breadcrumb NavXT Pugin
I've stopped to explore how to output custom part of worpress site taxonomy on the server-side. I just use jquery to copy active taxonomy branch from main menu and paste it to the page container I need.