I want to do the pagination for my custom post type "Employes", but if I use the WP_Query, I can use the attribute post_per_page, but the URL changed like this.../page/2. I want the URL changes by this way ...#2, because the former way I can't use tab content, Who can help me? Thank you so much!
Use this:
function custom_pagination_base() {
global $wp_rewrite;
$wp_rewrite->pagination_base = '{pagination-url-here}';
$wp_rewrite->flush_rules();
}
add_action( 'init', 'custom_pagination_base' );
Paste this code in theme function.php
{pagination-url-here} replace your uri segment
Related
Since woocommerce is using gutenberg blocks I can't find out how to edit the layout on the front end e.g. remove the image and wrap the title in a h2?
The templating functionality only seems to work with their custom fields and not the blocks rendered using js - https://docs.woocommerce.com/document/woocommerce-theme-developer-handbook/
I know I can fudge some things with css but it want solve all layout issues.
Thanks.
Woocommerce blocks
Front end of website
Try using the render_block filter you can find inside the homonym function:
add_filter( 'render_block', 'so59123547_render_block_filter', 10, 2 );
function so59123547_render_block_filter( $block_content, $block ) {
if( $block['blockName'] === 'woocommerce/NAME-OF-THE-BLOCK' ) {
// do what you want
}
return $block_content;
}
I would like to permanently set the default view in OpenCart 2.1.0.2 to list-view instead of grid-view. I do not want to give my visitors ability to switch to grid-view; hence I'd like to completely disable grid-view and keep only list-view. Any assistance would be greatly appreciated.
You can do that using two methods for default list view.
1st method: replace following code (catalog/view/javascript/common.js)
if (localStorage.getItem('display') == 'list') {
$('#list-view').trigger('click');
} else {
$('#grid-view').trigger('click');
}
and using the following code in place
if (localStorage.getItem('display') == 'grid') {
$('#grid-view').trigger('click');
} else {
$('#list-view').trigger('click');
}
2nd method: If you don't want/like to permanently remove grid view then remove the code in (catalog/view/javascript/common.js) and make following code in common.js only
$('#grid-view').trigger('click');
previously i made a navigation bar in a view page for which i wrote the function in corresponding controller but now i have to put this in main file (layout). But now i don't know where to write the function.
also i have to pass two variable to the layout file through the function that will contain the value of navigation bar.
I have already tried some method but it allows me to return only on value.
Basically i want to know that where can i write the below function to use it in main layout of yii2 basic
public function actionMenutest()
{
$query = new Query;
$data= $query->select('name,id')
->from('menu')->all();
$query2 = new Query;
$data2= $query2->select('name,menu_id')
->from('submenu')->all();
return $this->render('menutest',[
'data'=>$data, 'data2'=>$data2
]);
}
You can use EVENT_BEFORE_RENDER for this purpose. For advanced app the below code need to go into common\config\bootstrap.php file.
use yii\base\Event;
use yii\base\View;
Event::on(View::className(), View::EVENT_BEFORE_RENDER, function() {
$query = new Query;
$data= $query->select('name,id')
->from('menu')->all();
$query2 = new Query;
$data2= $query2->select('name,menu_id')
->from('submenu')->all();
Yii::$app->view->params['data'] = $data;
Yii::$app->view->params['data2'] = $data2;
});
Then in your main layout you can use your model as:
$data= $this->params['data'];
$data2= $this->params['data2'];
I have not used basic template as yet. But you can try the following:
Create a bootstrap.php file in config folder.
After that update the web/index.php file. Put the below code in that:
require(__DIR__ . '/../config/bootstrap.php');
Then put the above code in bootstrap.php file. Try it and let me know if you need any more help.
I'm not able to use an htaccess for my project therefore clean URLs doesn't work for routing. Is there a way to to use query params instead?
example
myf3project.net/user/show isn't possible. Instead I want to do something like this:
myf3project.net?path=user/show or
myf3project.net?view=user&action=show
You can also overwrite the $_SERVER['REQUEST_URI'] for this purpose:
$f3->route('GET /user', function ($f3) { echo "user"; });
$f3->route('GET /user/#action',function($f3,$params){
echo "user->".$params['action'];
});
if ($f3->exists('GET.path',$path))
$f3->URI = $f3->BASE.'/'.$path;
$f3->run();
and then just open
http://myf3project.net?path=user/show
Do you mean that mod_rewrite is not available? That's a problem indeed. You can however call $f3->mock to the rescue.
Here's a quick example:
$f3 = require('lib/base.php');
// Homepage
$f3->route('GET /',function($f3){
echo 'This is home. '.
'Click here to see the contact form.';
});
// Contact form
$f3->route('GET|POST /contact',function($f3){
echo 'This is the contact form. '.
'Click here to go back home.'.
'<form method="post" action="">'.
'<textarea name="message"></textarea>'.
'<button>Send message</button></form>';
if ($f3->VERB=='POST')
echo 'Submitted message:<br>'.
nl2br($f3->get('POST.message'));
});
// Workaround here: $f3->mock is used instead of $f3->run
$path=$f3->get('GET.path');
if (#$path[0]!=='/')
$path='/';
$f3->mock($f3->VERB.' '.$path,$_POST);
It's still kinda possible, unfortunately you have to build most on your own.
Very basic example:
<?php
$f3 = require 'lib/base.php';
$f3->route('GET /', function() use($f3) {
switch($f3->get('view')) {
case 'user':
// do something
break;
case 'admin':
// do something
break;
}
});
The "/" route should work even without .htaccess.
Based on #xfra35's answer, I propose a solution that will allow you to have paths like this:
/index.php/foo/bar
Instead of:
/index.php?path=/foo/bar
But you still can use query variables (like /index.php/foo/bar?test=123) and get them using $_GET['test'] or $f3->get('GET.test'):
Just replace your $f3->run(); with:
$path=$_SERVER['PATH_INFO'];
if (#$path[0]!=='/')
$path='/';
$f3->mock($f3->VERB.' '.$path.'?'.$_SERVER['QUERY_STRING'],$_POST);
As am totally new to YUI i dont have any clue about.I have just gone through this link to implement autocomplete using YUI http://developer.yahoo.com/yui/autocomplete/.
According to my requirement i need to assign a string array dynamically to datasource object instead of
var dsLocalArray = new YAHOO.util.LocalDataSource(["apples", "broccoli", "cherries"]);
something like
var dsLocalArray=new YAHOO.util.LocalDataSource(documentList[]);
where my documentList is String Array.How do i that?Thanks in advance for the help.
I would suggest you to use YUI3 than YUI2, the example you are showing which uses the YAHOO namespace which is YUI2.
YUI3 is simpler and better, you can get the docs here:
http://yuilibrary.com/yui/docs/autocomplete/
Example of implementing with YUI3 including highlighting feature:
YUI().use('autocomplete', 'autocomplete-filters', 'autocomplete-highlighters', function (Y) {
Y.one('#ac-input').plug(Y.Plugin.AutoComplete, {
resultFilters : 'phraseMatch',
resultHighlighter: 'phraseMatch',
source : ['Alabama','Alaska','Arizona','Arkansas','California']
});
});
Try to lok into the examples at the right bottom side panel in the above docs link.