How to provide option to show plugin in selected menus page? - wordpress

I am using a plugin in wordpress but it does not provide a option to which page i what to show that plugin.
What i done? I am showing you.Firstly i get menus names through this wordpress function:
$defaults = array(
'theme_location' => 'main-menu',
'depth' => 1,
);
wp_nav_menu( $defaults );
It shows menus like this:

While I feel like your question is incredibly incomplete, and I'm not sure of your technical level, I would highly recommend using one of two frameworks to create the options panel for the plugin.
They will provide an easy way to work with the settings api and create various field types etc.
have a look at the Redux framework or at CMB

Related

Any way to add metaboxes in custom settings page of custom post type in wordpress? [duplicate]

This question already has an answer here:
Add meta box to WordPress options page
(1 answer)
Closed 4 years ago.
Hi I would like to add metaboxes under custom settings page which is under a custom post type. I can create metaboxes for custom post types also I can create a theme options. But can't find any way to add the metaboxes on a custom settings page. Like my post type hierarchy is like below:
Products
- All item
- Add Item
- Product Category
- Product Settings
I want to add the metaboxes & create a options page on that settings page. Can you please guide me through this one.
I've been trying to follow this gist but can't find a way.
https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/options-and-settings-pages/theme-options-cmb.php
Also can you let me know if I can achieve something by tweaking this code where key|value operates
$cmb = new_cmb2_box( array(
'id' => $this->metabox_id,
'hookup' => false,
'show_on' => array(
// These are important, don't remove
'key' => 'options-page',
'value' => array( $this->key, )
),
) );
I've created the settings page by this code
add_submenu_page('edit.php?post_type=ch_product_showcase', 'Product Showcase Settings', 'Showcase Settings', 'edit_posts', basename(__FILE__), array( $this, 'chProductShowcaseSettingsOptions') );
I've done it many times. Use this code and tweak it to your needs:
https://gist.github.com/turtlepod/5203512
Found as a link in the comments of this page:
https://gist.github.com/bueltge/757903
Originally posted here:
Wordpress - Add meta box to options page
Normally I don't like answering with links to another site, but in this case the code is on gist and hopefully will never go away!

Wordpress 3.5 - How to only show the sub menu of a parent with wp_nav_menu?

I want to find the easiest way to get the child list of a specific page (stored inside Appearances > Menus tab) with wp_nav_menu function.
Example, I have this menu, called "primary_navigation" :
Home
Services
- Web
- Design
- Mobile
Contact
EXAMPLE OF CODE
<?php
wp_nav_menu( array(
'theme_location' => 'primary_navigation',
'container' => '',
'items_wrap' => '%3$s')
);
?>
How I can get only the items inside of Services tab, example :
Web
Design
Mobile
EXAMPLE OF CODE I SEARCHING FOR...
<?php
wp_nav_menu( array(
'theme_location' => 'primary_navigation',
'container' => '',
'child_of' => 'PARENT_ID'
'items_wrap' => '%3$s')
);
?>
I want to use wp_nav_menu function because it's easier for the client to manage navigation.
Thanks!
UPDATE :
I found this link : https://wordpress.stackexchange.com/questions/2802/display-a-portion-branch-of-the-menu-tree-using-wp-nav-menu/2809#2809
It work, but not completly and I found it a little bit complicated. With this solution, I can't get childs elements by parent ID and it seem to have problem with quote in the name.
If you have better approach, I'm really interested! :)
I believe I have a much better solution, in your example you would be specifying the parent_id that you are looking for. I wrote a plugin which enables you to simply specify the start_depth that you want. So if you wanted to show a secondary menu, ignoring the first level menu items, you would give a start_depth of 1 like this:
wp_nav_plus(array('theme_location' => 'primary_navigation', 'start_depth' => 1));
Of course you will need to install and activate the plugin before you can start using WP Nav Plus. It is available at my website for anyone who is interested: https://mattkeys.me/products/wp-nav-plus/
As a side note: This functionality is native to many other content management systems I've used, I wonder why it is not a default option in Wordpress? I got so sick of all the workarounds and their particular 'quirks' that I finally wrote my own solution.

how to list subpages in sidebar without widget - wordpress

I am trying to create a list of subpages of a parent page, which will appear in the sidebar of my wordpress site. This sidebar will appear on every page.
So for example, I have a page with an ID of 54. This page has 7 subpages. I would like to display these 7 pages in the sidebar (just the titles), as well as any more subpages that get added.
There is a currently a widget called 'Pages' that will do this, but I would like to do this via code directly in the sidebar.php rather than using a widget as there are a few constraints with using the widget.
Any help would be greatly appreciated.
Thanks
Try this link: http://codex.wordpress.org/Function_Reference/wp_list_pages
Specifically, look the 'depth' and 'child_of' parameters for the function.
Should be:
<?php wp_list_pages( array( 'depth' => 1, 'child_of' => YOUR_PAGE_ID_HERE ); ?>
furthermore, you can get the page id dynamically too of course.
To write custom code for such purpose will require you to execute php inside the widget. Try using this Php Code Execute Plugin

Wordpress Sticky Posts with Custom Post Types

So i need the ability to have a featured or "sticky" post in wordpress, and it occurred to me! Why not use the Sticky Posts facility, but after doing a bit of reading it seems that Wordpress decided to not include support for it in latest releases and they don't seem to be pushing any solution for future releases.
Now that leaves me in a predicament i wish to have the ability to have a featured post or custom post without using a category of such.
I've also seen a few people state they have hacked wordpress with possibly a function to add the ability of sticky posts to custom post types, shame they didn't share the source!
How would this be done?
You can do it with a custom field (post_meta) on the custom post type. Then fire a custom query that selects for the meta_value:
$args = array('post_type' => 'my_custom_post_type', 'post_status' => 'publish', 'meta_query' => array('relation' => 'AND', array('key' => 'is_sticky', 'value' => '1', 'compare' => '=', 'type' => 'CHAR')));
$sticky_posts = new WP_Query($args);
Should return an array of published posts of post_type: my_custom_post_type that have the sticky flag set.
Although I haven't tested the above code, I'm doing something similar and it works fine.
You can use this plugin, it has it's own limitations, but works pretty well if you don't need something elaborate.
You can save a custom meta with the name of "sticky" and add it the value "on" when the post is sticky. That can be done with a custom metabox and a checkbox.
Wordpress will automatically add the word "Sticky" on the backend posts listing table
You can retrieve a loop with your sticky custom posts by adding the values 'meta_key' => 'sticky' and 'meta_value' => 'on' to the args of your query
I posted a working solution as of WordPress 4.2 here:
https://wordpress.stackexchange.com/questions/90958/adding-sticky-functionality-to-custom-post-type-archives/185915#185915
Basically, it implies installing a small plugin and add a code snippet.
I have Wordpress 3.2.1, the latest version and I can sticky posts. It works for me on my site.

How do you remove a Category-style (hierarchical) taxonomy metabox

I was wondering if someone can help me with this. I'm currently following Shibashake's tutorial about creating custom meta-boxes that include taxonomy selection here: http://shibashake.com/wordpress-theme/wordpress-custom-taxonomy-input-panels .
They show how to remove the standard metabox Wordpress automatically creates for taxonomies using the remove_meta_box function. Only problem is that the function for some reason doesn't seem to work on taxonomies that work as categories ie ones where the hierarchical option is set to true. I know I have the function working because the ones set up as tags disappear easily enough. I can't if it just isn't possible or if there is something special I need to add in one of the parameters to make it work.
Example:
$args = array(
'hierarchical' => false,
'label' =>'People',
'query_var' => true,
'rewrite' => true
);
register_taxonomy('people', 'post',$args);
remove_meta_box('tagsdiv-people','post','side');
That works fine. If I set hierarchical to 'true, however, the meta box stays put.
Can anyone shed some light?
Found the answer asking over at the Wordpress side of StackExchange:
For taxonomies that work like tags, you use "tagsdiv-slug". But for ones that are hierarchical, you use "slugdiv". The answe can be found here:
Thanks to #Jan Fabry for his answer

Resources