How to add menù section to my WordPress template? - content-management-system

I am pretty new in WordPress blog and I am developing a blog with this template:
http://scorejava.com/wordpress351
As you can see at the top of the page there is a "menù" that only show the page in the site (at this moment: "Home" and "Pagina di esempio").
This menù is showed by the following lines of code into the header.php file:
<?php wp_list_pages('title_li=&depth=1'); ?>
So I think that this is not a true menù but only a list of the statics pages present on my blog.
If, in the administrator dashboard I go to the menù section in the "Position of themes" square say me that: "This theme has no support for menus but it is possible use the personalized menu widget to add every created menu in the sidebar"
So I think that my template have no definied a true menù section on the top (but only a list for the static pages). Can I add a true section where add a true menu? How can I do?
Tnx
Andrea

function dasboard_menu() {
global $menu;
$menu[6] = array( __('Orders'), 'read', 'edit.php?post_type=shop_order', '', 'menu-top menu-top-first menu-icon-orders', 'menu-dashboard', 'none' );
$menu[7] = array( __('Catalogue'), 'read', 'edit.php?post_type=product', '', 'menu-top menu-top-first menu-icon-catalogue', 'menu-dashboard', 'none' );
$menu[8] = array( __('Coupons'), 'read', 'edit.php?post_type=shop_coupon', '', 'menu-top menu-top-first menu-icon-coupon', 'menu-dashboard', 'none' );
}
add_action( 'admin_menu', 'dasboard_sub_menu' );

Your starting point is to register your menus in functions.php. Like this:
register_nav_menus(array(
'main_nav'=>__('Main','mythmeme'),
'footer_nav'=>__('Footer','mythmeme'),)
);
It's all in the codex.
You then just need to call the menu in your header.php (or footer.php):
<nav>
<?php wp_nav_menu(
array('theme_location' => 'main_nav')
); ?>
</nav>
Once registered and called you can you use dashboard > appearance > menu to create and add menus to your theme locations.

Related

How to link this button to another route in Laravel Bacpack

So i have this view below :
The button view that i want to route to another page
Theres a button named Go To Question that i want to link to edit-question route. This is the code for the button.
[ // CustomHTML
'name' => 'separator',
'type' => 'custom_html',
'value' => '<a href="{{$this->crud->setEditView(`backpack::crud.question`,3);}}"
target="_blank">Go to question ></a>'
],
Does anyone know how to do this ?
You can easily link to a Backpack page using the backpack_url() helper instead of Laravel's standard url(). That will also add the admin prefix that you've set in your config/backpack/base.php (by default admin).
But take note that you cannot add a link to a particular view in Laravel. You should point to a route, that points to a controller, that loads a view. So your button should look more like this:
[ // CustomHTML
'name' => 'separator',
'type' => 'custom_html',
'value' => '<a href="{{ backpack_url('question/3/edit') }}"
target="_blank">Go to question ></a>'
],
This will point to the Questions CRUD route, which will load QuestionCrudController, which in its turn will load the edit view - assuming you do have that CRUD.

What's the best way to site specific configuration in a multisite TYPO3 installation?

We have a TYPO3 9.5 installation with a bunch of different websites in it.
We want to store some custom configurations for each site (eg. show phone number in footer yes/no and something like this) and give the editors the possibility to change this in a simple way in the backend.
It would be nice if we can store these properties on the rootpage of each site but be able to overwrite (some) properties on sub pages if needed.
Similar to the page properties that fluidtypo3/flux brings.
Is there a possibility to achieve this with TYPO3 core and a custom extension? Eg. by extending the page table or adding custom table?
You need to differ between a site configuration and regular pages!
The site configuration is valid for the full site, so for every page
A page can be different on a page level
Both use cases are valid, so let's explain in detail
Extending the site configuration
The site configuration can easily be extended by creating the file <site-extension>/Configuration/SiteConfiguration/Overrides/sites.php
<?php
defined('TYPO3_MODE') || die('Access denied.');
call_user_func(
function ($table) {
$GLOBALS['SiteConfiguration'][$table]['columns']['trackingCode'] = [
'label' => 'Label',
'config' => [
'type' => 'input',
'eval' => 'trim',
'placeholder' => 'GTM-123456',
],
];
$GLOBALS['SiteConfiguration'][$table]['types']['0']['showitem'] .= ',--div--;Extra,trackingCode';
},
'site'
);
The value of the new field trackingCode can then be easily fetched, e.g. by TS with data = site:trackingCode. As an alternative you can also use the SiteProcessor to get access to the site configuration in a FLUIDTEMPLATE.
Extending pages
Create the file <site-extension>/Configuration/TCA/Overrides/pages.php
<?php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'pages',
[
'trackingCode' => [
'exclude' => true,
'label' => 'A label',
'config' => [
'type' => 'input',
]
],
]
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'pages',
'--div--;Extra, trackingCode'
);
and `ext_tables.sql``
CREATE TABLE pages (
trackingCode text NOT NULL
);
and you get access to the field with TypoScript and within FLUIDTEMPLATE with {data.trackingCode}.
Using slide
By adding trackingCode to the comma separated list in [FE][addRootLineFields] (use the Install Tool > Settings > Configure Installation-Wide Options it is possible to override the value for all subpages.
The following TypoScript will get up the rootline and return the 1st value set.
lib.code = TEXT
lib.code.data = levelfield:-1,trackingCode, slide

How to add a class to a postLink form - CakePHP 3.4

Is it possible to add a class to the hidden form created by CakePHP's postLink form helper?
Here's my code
Form->postLink(
' ' . __('Delete'),
['action' => 'delete', $this->fetch('item')],
['confirm' => __('Are you sure you want to delete # {0}?', $this->fetch('item'))
,'escape' => false
,'title' => __('Delete')
,'class' => 'btn btn-danger btn-xs isAction'
]) ?>
Note that I'm not looking to add a class to the link that gets created.
Any ideas are welcome!
There's pretty much only one way currently, and that would be to change the formStart template temporarily, something along the lines of this:
// read current template and set the new one
$formStart = $this->Form->getTemplates('formStart');
$this->Form->setTemplates([
'formStart' => '<form class="hiddenFormClass"{{attrs}}>'
]);
echo $this->Form->postLink(/* ... */);
// set the template back to its previous state
$this->Form->setTemplates([
'formStart' => $formStart
]);
It's also possible to reset the templates to their default state using the resetTemplates() method, however this would reset all possible changes made to any of the templates, so it's probably better to play it safe as shown above.
See also
Cookbook > Controllers > Views > Helpers > Form > Customizing the Templates FormHelper Uses
API \Cake\View\Helper\FormHelper::setTemplates()
API \Cake\View\Helper\FormHelper::getTemplates()
API \Cake\View\Helper\FormHelper::resetTemplates()

How to change position of woocommerce "added to cart" message

I am using woocommerce version 2.3.13 and I want to change position of woocommerce messages like "Product was successfully added to cart", which appears on the top of the product page when I click on "add to cart" button.
I want this message to appear somewhere else.
I've tired many solutions including this by removing 'woocommerce_show_messages' on 'woocommerce_before_single_product' hook
code: remove_action( 'woocommerce_before_single_product', 'woocommerce_show_messages' );
and then calling woocommerce_show_messages(); function where I want the message to appear but with no luck.
Anyone please help me in this regard.
EDIT:
I've forgot to mention that I am using storefront theme and using custom template for single product.
And these messages are appearing at the top of page by default.
The messages 'Product was successfully added to cart' are woocommerce notices.
These messages are printed by the function
<?php wc_print_notices(); ?>
Try changing the position of this function in template.
To add notices via hooks
add_action( 'woocommerce_before_shop_loop', 'wc_print_notices', 10 );
add_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
STOREFRONT Theme Edit:
** Works with Woocoommerce: 3.1.2 + Storefront: 2.2.5 **
In storefront theme the wc_print_notices is hooked into storefront_content_top
so to remove messages from top in storefront theme you need to add following code in functions.php
remove_action( 'woocommerce_before_shop_loop', 'wc_print_notices', 10 ); /*Archive Product*/
remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 ); /*Single Product*/
remove_action( 'storefront_content_top', 'storefront_shop_messages', 1 );
and add function
wc_print_notices();
Wherever you want notices to appear.
EDIT: The messages will not appear on Single Product Page and Archive Product Page. Though they might appear on any other woocommerce page(cart, checkout, etc).
This works for me (WooCommerce 3.2+) (based on this answer for #LoicTheAztec)
add_action( 'wp_head', 'reposition_sf_messages' );
function reposition_sf_messages(){
if( is_product() ) {
remove_action( 'storefront_content_top','storefront_shop_messages',15 );
}
remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 ); /*Single Product*/
add_action('woocommerce_product_meta_end', 'storefront_shop_messages', 1 );
}
If someone is still looking for a solution here it goes.
you can use something like
remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );
Now put this code where you want to show the notices.
<?php wc_print_notices(); ?>
I had the same problem. I have woocommerce 6.3.1 installed and nothing worked for me. In the end I started looking at the woocommerce files and found that it is "woocommerce_output_all_notices".
So I went to my functions.php of my child theme and put the following:
//Remove for original position
remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );
//Move under cart button (option 1)
add_action ( 'woocommerce_single_product_summary', 'woocommerce_output_all_notices', 35 );
//Move under cart button (option 2)
add_action ( 'woocommerce_single_product_summary', 'mover_mensaje_product_added', 35 );
function mover_mensaje_product_added() {
echo woocommerce_show_messages();
}
//Change text (optional)
add_filter( 'wc_add_to_cart_message_html', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
$message = '¡Estupendo! Ya tienes el producto en tu carrito :)' ;
return $message;
}
From option 1 and option 2, you should only choose 1. Or you put one or the other. I only give you alternatives that have worked for me, and in my case both options are valid.
Have you tried this:
remove_action( 'woocommerce_before_single_product', 'woocommerce_show_messages' );
add_action( 'woocommerce_after_single_product', 'woocommerce_show_messages', 15 );
Here third parameter is for positioning priority
i think this will help you ............
add_action('woocommerce_before_my_page', 'wc_print_notices', 10);
Now go to your page, where you want the messages displayed, and add
<?php
do_action( 'woocommerce_before_my_page' );
?>
This is the complete code to add in functions.php of the theme.
function move_woocommerce_message(){
remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
add_action( 'woocommerce_single_product_summary', 'wc_print_notices', 35 );
}
add_filter('wp', 'move_woocommerce_message');

dokuwiki: how can I hide media manager link from non logged in users

In dokuwiki how can I hide "media manager" link or any other link on the top, from non logged in users?
one way is changing the template like this:
in /lib/tpl/dokuwiki/tpl_header.php:
<?php
if ($INFO['isadmin']) {
tpl_action('recent', 1, 'li'); //recent changes
tpl_action('media', 1, 'li'); //media manager
tpl_action('index', 1, 'li'); //sitemap
}
?>
Not exactly what you're looking for (and maybe a bit late anyway), but here's a way to disable the Media Manager link for all (including logged-in) users:
go to admin panel, Configuration Settings;
search for Disable DokuWiki actions (option name: disableactions);
in Other actions, add keyword media (see reference here).
Note that this will hide the link for everyone, but users with writing access can still launch the media manager by clicking on corresponding button when editing pages.
If no user is logged, $INFO["userinfo"] is empty
in /lib/tpl/dokuwiki/tpl_header.php
replace
tpl_toolsevent('sitetools', array(
tpl_action('recent', true, 'li', true),
tpl_action('media', true, 'li', true),
tpl_action('index', true, 'li', true)
));
with
if(!empty($INFO["userinfo"])) {
tpl_toolsevent('sitetools', array(
tpl_action('recent', true, 'li', true),
tpl_action('media', true, 'li', true),
tpl_action('index', true, 'li', true)
));
}
My solution with "grebo"
find inc/Action/Media.php
edit method tplContent():
public function tplContent() {
global $INFO;
if ( empty($INFO['userinfo']) ) {
echo "<p>No way</p>";
return;
}
tpl_media();
}
So only users - but not anonymous - can see media manager.
Create a plugin. Let's assume the plugin name is nositetoolsanon, so you need to create a file under lib/plugins/nositetoolsanon/action.php.
<?php
if(!defined('DOKU_INC')) die();
class action_plugin_nositetoolsanon extends DokuWiki_Action_Plugin {
public function getInfo(){
return array('date'=>'2017-08-25', 'name'=>'No sitetools for anonymous users', 'author'=>'Phy25');
}
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('TEMPLATE_SITETOOLS_DISPLAY', 'BEFORE', $this, 'action_link');
}
public function action_link(&$event, $param){
global $INFO;
if(empty($INFO["userinfo"])){
// more robust check by ACL: global $ID; if (auth_quickaclcheck($ID) < AUTH_READ)
$event->preventDefault();
}
}
}
This method applies to any template and won't be overwritten by updates.
HINT: If you want to hind namespaces for users who are unable to read, try to set $conf['sneaky_index'] = 1 in the config file, though it may cause issues if deeper namespaces have higher permissions than the ones above.
I had this question myself recently and found the selected answer to be insufficient for me. I'm pretty sure it didn't work because I'm using the Codowik template rather than the default. This is what I came up with using sivann's answer.
I edited /lib/tpl/codowik/tpl_header.php and added this at the top:
<?php
if (!$INFO['isadmin']) {
echo "<script>
var newStyle = document.createElement('Style');
newStyle.innerHTML = '#codowiki_search_ul a {display: none;}';
document.head.appendChild(newStyle);
</script>";
}
?>
It rather hackish, but I don't have time to dive deeper into how the template is implemented, and it works!
I wanted only the sitemap to be visible to visitors and registered users (I use the site as a blog), so only wanted recent changes and media links to be visible to me (administrator).
This is the code I changed in "Greebo", in inc/Menu/SiteMenu.php
protected $types = array(
//'Recent', // comment out stuff not required
//'Media',
'Index' // leave sitemap for spiders
);
// add this function
// remove the "&& $INFO['isadmin']" to allow all logged in users to see options
public function __construct(){
global $INPUT;
global $INFO;
if($INPUT->server->str('REMOTE_USER') && $INFO['isadmin']){
$this->types = array( 'Recent', 'Media', 'Index' );
}
}
My solution will may be hide too much information, but here we go:
Login as admin
Go the management section
Scroll to ACL (Access Control List) Management
Set User/Group „#all“ Permissions to „None“