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;
}
Related
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');
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
I am using the Nivo Slider for the first time and it is absolutely awesome however I do have a couple of issues.
I have it integrated within a CMS and this allows the user to add up to 5 images.
If there is only one image however, I would like to just hide the thumbnails and stop any transitions, as in sliding the same image in again and again.
Now is this something I would do with JQuery or should I be editing the 'jquery.nivo.slider.js' file? Or is it potentially something I could potentially accomplis in both?
I guess I am looking to do something like:
if images < 1 {
transition = false;
thumbnails = hide;
}
Hopefully that makes sense.
Thanks for your time and help.
UPDATE
Okay so I have managed to hide the thumbnails if there is only one image by adding the following to the jquery.nivo.slider.js file:
if (vars.totalSlides < 2)
{
$('.nivo-controlNav').remove();
}
I now want to be able to change one of the settings in the following piece of code based on the same rule but am not sure how to do this:
$.fn.nivoSlider.defaults = {
pauseOnHover: 'false',
......
}
I would change the config array and initialize the slider like this:
// nivo config array
var nivoConfig = {
slices: 30, // For slice animations
boxCols: 16, // For box animations
// put all your init config here but exclude 'effects'
}
if(imagesCount < 2) {
nivoConfig['effects'] = 'none';
} else {
nivoConfig['effects'] = 'random';
}
$('#slider').nivoSlider(nivoConfig);
Try it out, it should work in a way like this.
I had this exact same problem; Johnny's code worked perfectly, but I wanted to elaborate for people who may be having problems with this. You'll want to insert:
if (vars.totalSlides < 2) {
$('.nivo-controlNav').remove();
}
on or around line 158 in the jquery.nivo.slider.js file (within the if(settings.controlNav) {} conditional). Otherwise it won't work.
I am struggling with the paginator in Cakephp 2.0. While I am trying to migrate my application to 2.0 I cant find any solution to jump directly to the last page. In 1.3 it was quiet to do that from outside like this:
echo $this->Html->link(__('Flights'), array('controller' => 'flights',
'action' => 'index','page' => 'last'));
but this little trick putting 'page:last' in does not work anymore in 2.0. Of course there is a Paginator function called last, but this would only help if I would be already inside the app. My Problem is to access from an outside link directly the last page of the paginator.
This is the simple way:
echo $this->Paginator->last('Any text');
Other way to get the number of the last page is:
echo $this->Paginator->counter(array('format' => '{:pages}'));
Then you can use it to generate your link.
For more info:
http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::last
Shortly after creating a bounty for this question I found the solution to MY problem using CakePHP 2.2.4. I was trying to accomplish the same task but instead using version 2.2.4 instead instead of 2.0. Basically if I had a link that looked like http://www.domain.com/articles/page:last that the controller's pagination method would know what page to go to and display the correct results (articles) for that page. For example, if I have 110 articles and the pagination limit is set to 25, by going to that URL it would display page 5 of 5, showing records 101-110. I also wanted the same capability if I go to “page:first”.
I needed to change my library file lib/Cake/Controller/Component/PaginatorComponent.php.
I changed
if (intval($page) < 1) {
$page = 1;
}
To
if ((intval($page) < 1 && $page != "last") || $page == "first") {
$page = 1;
}
I also added
if($page == "last"){
$page = $pageCount;
}
After the line
$pageCount = intval(ceil($count / $limit));
Christian Waschke, with this solution, you can use the same link helper exactly how you wrote it in your question. For me, the link helper looked like this
<?php echo $this->Html->link('Go to Last Page', array('controller' => 'articles', 'action' => 'index', 'page' => 'last')); ?>
You can 'calculate' the last page yourself if 'last' is passed as the page number;
I would discourage making modifications in the CakePHP library files as this will make it hard to perform upgrades in the future.
Basically, the PaginatorHelper uses viewVars that are calculated and set by the PaginatorComponent, as seen here: https://github.com/cakephp/cakephp/blob/master/lib/Cake/Controller/Component/PaginatorComponent.php#L212
You can replicate this in your action; for example:
public function index()
{
if (!empty($this->request->params['named']['page'])) {
switch($this->request->params['named']['page']) {
case 'first':
// replace the 'last' with actual number of the first page
$this->request->params['named']['page'] = 1;
break;
case 'last':
// calculate the last page
$limit = 10; // your limit here
$count = $this->Flight->find('count');
$pageCount = intval(ceil($count / $limit));
// replace the 'last' with actual number of the last page
$this->request->params['named']['page'] = $pageCount;
break;
}
}
// then, paginate as usual
$this->set('data', $this->paginate('Flight'));
}
To improve this, this logic should be moved to a separate method, or to a behavior. However; as seen above, it is not required to make modifications in the PaginatorComponent!
Also note that the 'find(count)' in my example does not take additional conditions, they should be added if required
If you have a look in the CakePHP 1.3 source for paginate(), the code above is comparable; https://github.com/cakephp/cakephp/blob/1.3/cake/libs/controller/controller.php#L1204
Would anyone please advise how in jade for nodejs I can truncate a string to a number of characters/words, ideally conscious about the HTML markup within the string?
This should be similar to Django's truncatechars/truncatewords and truncatechars_html/truncatewords_html filters.
If this doesn't exist in jade, which way is right to go? I'm starting my first nodejs+express+CouchDB app, and could do it within nodejs code but it seems that filters are much more appropriate.
I would also consider writing a filter like this (and others) if I knew how :))
Just a quick illustration:
// in nodejs:
// body variable comes from CouchDB
res.render('home.jade', { title : "test", featuredNews : eval(body)});
// in home.jade template:
ul.thumbnails
each article in featuredNews.rows
a(href="#"+article.slug)
li.span4
div.value.thumbnail
img(align='left',src='http://example.com/image.png')
p!= article.value.description:truncatewords_html(30)
So I've made up the truncatewords_html(30) thing to illustrate what I think it should be similar to.
Will appreciate any ideas!
Thanks,
Igor
Here is a little "truncate_words" function:
function truncate( value, arg ) {
var value_arr = value.split( ' ' );
if( arg < value_arr.length ) {
value = value_arr.slice( 0, arg ).join( ' ' );
}
return value;
}
You can use it before sending the string to the template, or in the template using a helper method.
cheerio is a nice little library that does a subset of jquery and jsdom. Then it's easy:
app.helpers({
truncateWords_html : function(html, words){
return cheerio(html).text().split(/\s/).slice(0, words).join(" ")
}
})
Then, in a jade template use:
#{truncateWords_html(article.value.description, 30)}
This looks like a generic way to add any filters, hurray! :))