I have Two CPT as "Dress" and "Casual" and I would like to position them close to each other exactly after the "Dashboard" in the Menu.
I have this code in my custom post type for both:
'menu_position' => 2
how ever the result is displaying as:
the "Post" positions after the "Dress"! can you please let me know why this is happening and how I can keep all CPT after each other before the "Post".(I have 5 Custom Post Type)
Thanks
If Wordpress already has a menu item in the menu_position that you declare then it is moved to the next free position. Your issue is that Dashboard is in position 2 and then a separator is in position 4, so the second of your Post Types is moved to the next free position which is 6 (Posts is in position 5).
Note that Menu items are added in the order in which they are registered, so if they have the same menu_position, Post Types registered first will appear closer to the top of the menu.
However, you can move the default WP menu items if you so wish, thus achieving your desired display.
If you specify your menu_position as 6 and 7 for your custom Post Types, you can add this to move the separator to position 8 and Posts to position 9 -
add_action('admin_head', 'my_edit_admin_menu');
function my_edit_admin_menu(){
global $menu;
$menu[8] = $menu[4]; // Copy 'separator1' to a new menu location
unset($menu[4]); // Unset separator1 (from original position)
$menu[9] = $menu[5]; // Copy 'Posts' to a new menu location
unset($menu[5]); // Unset Posts (from original position)
ksort($menu); // Sort the menu
}
Note - the action admin_head is called after your custom Post Types are registered (using the init action). Because of this, you must ensure that your given menu_position values do clash with those of default menu items. If there is a clash, WP will move them before you get a chance to reorder the default items.
See the docs for menu_position in the Arguments section of the Function Reference for register_post_type() for the current WP default menu positions (although I believe that it is currently out of date for version 3.8). If you are ever unsure how the menu is organised, add this to the above code to output the full menu in the admin area -
echo '<pre>WP Admin Menu: '; print_r($menu); echo '</pre>';
FYI - I notice that you are using an image as the icon for you custom Post Types. As of WP 3.8, these were removed from the default admin dashboard in favour of DashIcons.
To make your Post Types look as pretty as the rest simply use the menu_icon argument, picking any of the icons from this page. To get the relevant name, click one and then look at the top of the page; the first icon is called dashicons-menu, for example.
if two menu items use the same position attribute, one of the items may be overwritten so that only one item displays! Risk of conflict can be reduced by using decimal instead of integer values, e.g. 2.3 instead of 2.
check here https://wordpress.stackexchange.com/questions/8779/placing-a-custom-post-type-menu-above-the-posts-menu-using-menu-position
Related
When I use vc_map() to add a new element to the content element list there is the category parameter to put the element in a certain tab.
If there are to many category tabs, VC will put some of them in a dropdown list on the right hand side. Is there a way to rearrange the order of all tabs?
There's a filter that can be hooked into to rearrange the order of the element categories: vc_add_element_categories.
For example:
add_filter( 'vc_add_element_categories', 'rearrange_element_categories', 10, 1 );
function rearrange_element_categories( $tabs ) {
// rearrange the tabs according to your needs
return $rearranged_tabs;
}
Don't know why someone would need this? Still you can arrange this as per your choice by jumping into plugin's code.
Con:
It will get reset, when in future you will be updating the plugin. And as per our understanding for WPBakery Page Builder plugin, you can't survive by without updating it.
I know there are 357,982 other posts about this BUT they all kinda lack something ie. an actual example that works for those of us who don't write 4,594,334 line of code every day.
SO - As it stands the scenerio is:
A plugin that registers a custom post type
A sub-menu you want to hide
What next?
The best solution I have found is actually pretty easy and requires a bit of inspection of the source and a good understanding of what to look for.
In this example woocommerce is registering the custom post type 'product' with a sub-menu that appears as 'Product Options'. We want to hide this for non-admin users.
Doing an inspection of the menu items we find that the hyperlink for the parent menu is 'edit.php?post_type=event_ticket' - looking a little further we see that the hyperlink for the sub-menu is 'https://websitename.com/wp-admin/edit.php?post_type=product&page=product_attributes'
We will use the 'add_action' hook as shown below. Please note that we are using the url for the parent menu however we are ONLY using the page parameter for the child.
add_action('admin_menu', 'remove_menu_pages', 999);
function remove_menu_pages()
{
if (current_user_can('manage_options') == false)
{
//1st parameter is parent URL | second is the 'page' parameter from the child url
remove_submenu_page('edit.php?post_type=product', 'product_attributes');
}
}
Add this to your functions.php and then login as a non-admin user and the submenu should now be hidden.
Apologies if the title is a bit confusing, but this is a problem specific to the CMS Concrete5.
I am working on a news/media related site, which consists of a main page which has 3 seperate pagelist blocks, with a layout as shown in the mockup attached.
For a page to appear in the featured pagelist (highlighted green), it needs to have the page attribute is_featured set to true. The 6 block pagelist (highlighted in red) is set to show ALL pages, including featured. Both pagelists are set to order by date, with the newest showing first.
The problem I'm having, is that when a content writer publishes a new page that is featured, I get immediate duplication with the same page listed in the top left of the 6 block pagelist. Given perhaps a day or so, as new 'non-featured' content gets added, the 'duplicated' page issue becomes less of a problem as it moves down the list, and onto the 2nd page (I have pagination on for the red block).
I'm using the standard Concrete5 pagelist block, and have custom templates which are just view.php files for the various lists (featured, 6 pages and sidebar list).
To remove the duplication, I tried adding some code in the view.php of the 6 pages template which would 'filter out' any featured page published in the last 24 hours. Whilst this does work, what I found was that I was then the 6 page pagelist would then show just 5 pages, and an empty gap for the 'filtered out' page.
My question is, is there a clean and better way of preventing duplication across pagelists? I don't want to have to set pagelists to only show certain categories (thus having no overlap whatsoever), but there must be a way to implement something that takes this particular issue into account?
In your "6 item pagelist" Page List block custom template, add the following code above your foreach ($pages as $page) {...} loop.
$list->filterByIsFeatured(false);
$list->setItemsPerPage(6);
$pagination = $list->getPagination();
$pages = $pagination->getCurrentPageResults();
What this does is take the existing $list (Concrete\Core\Page\PageList object) and gets 6 non-featured pages from the page results. The options, sorting, and filtering set in the Page List block form should be preserved by reusing $list.
The $list object is set here:
https://github.com/concrete5/concrete5/blob/develop/concrete/blocks/page_list/controller.php#L225
So I've got a content type of "News" and then a View which shows a list of News nodes as a menu item.
Is there any way to highlight the News View in the menu tree when you're viewing a News node?
I'm sort of aware of why this doesn't work, and why doing this might be hacky, but there's got to be a way to have a "default" menu item or something that a node can show up under.
Actually, I found a module that does basically what the template.php answer above does, by allowing you to assign a default menu item by content type.
It's called Menu Trails. Here is an excerpt from its project page:
... adds some common-sense usability to Drupal's menu system
Menu Trails implements primary/secondary links which keep the current menu trail "active" or highlighted. A handy snippet ready to go into your template.php is included.
The module provides a means of broadly categorizing nodes (by type or taxonomy) as falling "under" a known menu item. These nodes are not added to the menu tree (keeping the menu admin system sane) but they will trigger the functionality above -- preserving navigation state for the user -- when viewed.
New for 6.0: Menu Trails can also set breadcrumbs for nodes, keeping them in sync with the trail.
New for 6.0: Menu Trails is now Organic Groups aware, so nodes can be designated to fall "under" the first group node they belong to.
New for 6.0: A token is exposed to pathauto (and other token-aware modules) allowing for the menu trail to be used in automatic path alias creation.
Assuming the answer to my above comment is "yes," this is something you can accomplish through the template.php file in your theme folder
The final solution will depend on your settings, but generally most of the action will happen inside phptemplate_preprocess_page
// Simplified, and untested in this form
function phptemplate_preprocess_page(&$vars) {
if (isset($vars['node'])) { // if we're looking at a node
$body_classes[] = (($vars['node']->type == 'News') || (arg(0) == 'News')) ? 'news_page' : ''; // Page is news page
}
else if (arg(0) == 'taxonomy') {
// ... Special handling for news taxonomy pages, if you want
} else {
$body_classes[] = "page-type-" . arg(0);
}
$body_classes = array_filter($body_classes); // Out! Out! Damn empty elements!
$vars['body_classes'] = implode(' ', $body_classes);
}
This will give the you the body.news_page style class to work with, and you can combine that with the style of your news menu block to make it appear how you like.
if Menutrails doesn't work (for me it didn't) you can do it yourself by something like:
$somenode = menu_get_item('node/5');
menu_set_item($somenode);
I have found you have more control if you do something like this in hook_nodeapi().
// this code worked for me
$somenode = menu_get_item();
$somenode['href'] = 'node/5';
menu_set_item(NULL, $somenode);
You may need to set the weight of your custom module to be heavier than core modules: at least 1
I would like a page that displays a list of nodes (I can do this part with the Views module) and then also displays the details of a single node below the list. Ideally the details will update via Ajax when a node in the list is clicked, but reloading the page would be fine for a start.
I'm just starting to get into Drupal and the number of levels at which I can do stuff is somewhat overwhelming. For example should this be a View page with a customised block at the bottom? A page with two blocks (one for the list one for the item)? If so how would they communicate the node ID? Is there already a module that will do this for me? Maybe I should write my own module? And so on. If anyone with a better general understanding of Drupal could point me in the right direction it would be appreciated.
Edit:
Thanks for the answers so far, I think they point out that I missed out an important detail in my original question though. So, some more details:
I would like this page to effectively be a user's home page. As such my view is restricted to showing nodes that they've created. Editing the default node page would give me the problem of which node to send the user to when they log in (which may be possible I guess) and also would mean that I presumably couldn't view the node without also seeing the view?
I have been trying another tack which is to create page node which includes the View (called user_home) using some PHP. I have also set the View control to create a link for each node in the list and include the node id in that link e.g. http://localhost/drupal-6.10/?q=node/13/12 (where 13 is the node ID of the page I have created and 12 is the node ID of the item in the list).
<?php
//output the user_home view
print views_embed_view('user_home', $display_id = 'default');
?>
<br/>
<hr/>
<br/>
<?php
$queryparam = $_GET["q"];
// find the second /
$index = strpos($queryparam, '/');
$index = strpos($queryparam, '/', $index + 1);
$displayNodeId = substr($queryparam, $index + 1);
$displayNodeId = (int)$displayNodeId;
if ($displayNodeId > 0)
{
$displayNode = node_load($displayNodeId);
print node_view($displayNode);
}
?>
Now, this works, but I'm sure their's a more drupal friendly/compliant way of doing things (and the query string parsing is a nasty hack).
The canonical solution for this is to use a block in the "content top region" and the full node in content region.
The most basic way of achieving this is to simply display the node page normally and, with a theme having the content top region (Garland doesn't, Zen classic does), create a Views block containing the list you want and place it in that region. you can use the path as the argument to the View so its contents can depend on the currently displayed node. Then, define the visibility of the block to only match the conditions you want, probably to display only on node pages, or maybe on node pages of a specific content type. For this, use the PHP visibility mode for the block, and do something like
// Filter args for safety
if ((arg(0) == 'node') && is_numeric(arg(1)) {
$node = node_load(arg(1);
return is_object($node) && ($node->type == 'the_content_type_i_want');
}
else {
return FALSE;
}
That way the block will be displayed only when you want it.
If your theme does not have this feature, Panels provide a way for you to divide the page and place the view in one panel and the full node in an other one.
I would do that as following. Set Page specific visibility settings for your Views block with nodes list to be shown only on that nodes, Pathauto module can be helpful here also for managing bunch of nodes paths.
The custom pager might work for you.
http://drupal.org/project/custom_pagers
You first create a View for the pager to work on; this could be all posts by a certain user or whatever you want -- it's as flexible as any other View.
You don't need to provide forward-back links like a standard pager (and the default) -- with custom_pagers you get a $nav_array variable to play with that contains all the nodes in your view.
With that you should be able to create a table or list of links.
Generating secondary menu based on node titles