11ty Pagination Returns number in file structure - how do I prevent this from happening? - permalinks

I'm trying to create a page per item of data from my CMS in 11ty. The data has pulled through nicely, and each page outputs nicely. However, when created a permalink I'm getting:
public/page-title/1/index.html
Where /1/ is the iteration of the creation of the page. I've never come across this with 11ty before - does anyone know why this happens and how I can prevent it? The docs weren't particularly helpful - saying it would happen but not why or any work arounds.
Thanks!

If you want to remap the permalinks for pagination, you can set the permalink front matter variable, which supports template strings (11ty docs).
You can change the permalink to be whatever you want, as well as access the paginated object (made simple with an alias). For example, if you have a slug property on your aliased object, you might want something like this:
---
pagination:
data: cmsdata
size: 1
alias: item
permalink: "public/page-title/{{ item.slug }}/index.html"
---

Through further research it turned out the problem was through using permalinks in eleventyComputed - there is a workaround as detailed in this thread:
https://github.com/11ty/eleventy/issues/1555
TL;DR: set permalink to : "/" before setting your permalink to the path you want in eleventyComputed

Related

content area not found in my page with elementor

I just started with Wordpress and I published a website a few weeks ago. Today I wanted to edit the homepage, but I get the following error:
Sorry, the content area was not found in your page. You must call the_content function in the current template, in order for Elementor to work on this page.
I haven't edited my homepage and it worked perfectly a couple of weeks ago. Is there someone that can help me fix this issue?
If you are using any shortcode on your page and you are fetching post on that page and looping through the post in a while loop. Please add this after the loop ends. No sure why but this always cause issue for me.
wp_reset_postdata();
Code will look like this:
$posts= new WP_Query($args);
while ($posts->have_posts() ) : $posts->the_post();
.....
.....
.....
endwhile;
wp_reset_postdata();
It doesn't matter it's a shortcode or what if we are doing something like above make sure to add wp_reset_postdata();
This is one of the issues that I usually face. There can be other reasons too.
Probably you've edited the page template from Templates -> Theme Builder -> Single. Anyway, even if you don't, you can fix it that way: Go to Templates -> Theme Builder -> Single -> Add New, then select page and create a template for all single pages (make sure that you drag the page content widget in the template). This should overwrite your theme single page template (which misses the content function).
Just make sure your 'Home Page' and 'Posts Page' are different, otherwise you get your page mixed up and this error occurs.. Worked for me!
You can verify this setting in Appearance>Customize>Homepage Settings :)
The Answer to this error is to check the structure of your permalinks. Try to save your permalinks one more time. Also, try to change the permalink structure to “Plain”. Some servers do not allow to write to the .htaccess file and as a matter of fact, you cannot always modify your permalink structure and edit with Elementor.
I found myself in the same place yesterday and freaked for a moment and did some research to find out why I was receiving the error and came across this page. Believe for me it occurred due to the situation Ed Jones posted about above, I had inadvertently edited the post template. But a fast and easy fix was to go back to an earlier revision of the page in my history. That solved my problem quickly.
Add the_content() at the end of your templates

Set wordpress query before template

I have a business goal forcing me to try to change the global wordpress query after the URL has been determined, but before the templates start outputting variables in the context of the original post. I need to be able to use a plugin to check some meta values on the original post, and then change the query to represent another post object to display different data without changing the url.
I've tried using setup_postdata() what seems like everywhere.
(tried including wp_reset_query();)
global $post;
$post = get_post(145, OBJECT );
setup_postdata($post);
However, the template is still outputting the original query.
I'm open to other solutions. Thanks in advance.
add_action('wp_loaded', function(){
query_posts(array('p'=>145,'post_type' =>'any'));
});
This worked out fine. It can be added just about anywhere. However, it messes up page templates, and displays pages as if they're single.php!!! If I can get around that, then I'll be in good shape. Help?
EDIT: Got it working. I have to check and use p for posts, and page_id for pages. So long as those are set, the templates will follow correctly. Otherwise it was trying to apply the standard post template to pages.

Appending query parameter to Woocommerce category URL

I'm trying to force display the list view in my Woocommerce store but I can't seem to get it working.
The theme has support for list view and you can force it by appending "?product_view=list" so a category URL becomes:
http://subliminalscience.com/product-category/icbch-hypnosis-certification/?product_view=list
Instead of the default one:
http://subliminalscience.com/product-category/icbch-hypnosis-certification/
I added this Rewrite Rule to my htaccess but it doesnt:
RewriteRule ^product-category(.*)$ http://subliminalscience.com/product-category$1?product_view=list
It seems Wordpress ignores this Rewrite rule. Any ideas?
I'm surprised this answer stands as the only one.
Making changes in .htaccess to force this sort of behaviour seems really unnecessary and obviously isn't useful for others trying to solve this issue, especially those users on nginx servers or on shared hosting without .htaccess access.
You should try to fix this in PHP using an action.
Looking at your question, I can tell that theme you have is checking for GET data in the URL bar, which is the ?key1=value1&key2=value2 part of an URL. GET is an HTTP method that you can read about here if you want to learn more.
You can actually set GET data in PHP, and you can safely put this into your functions.php file.
You will want to create a function that simply checks the current page, and if it's a product category page sets the GET data.
At the bottom of your functions.php, you'd want to add something like this:
<?php
//Force all category pages to list view.
add_action('woocommerce_before_main_content','force_category_list_view', 5);
function force_category_list_view(){
if(is_product_category()){
$_GET['product_view'] = 'list';
}
};
?>
I actually can't test this, but I think it'd work. Essentially, in the woocommerce template archive-product.php, the first action that runs is 'woocommerce_before_main_content'. What we're doing is calling our function, which checks the page is indeed a product category. If it is, it sets the GET variable as list, which is exactly what the URL is telling the page to do already.
Mainly this is just a better practise than altering your .htaccess, but someone determined could also override that GET data by changing the URL to read ?product_view=list&product_view=xyz I can't imagine this would be an issue in this instance, but in other instances it might be.

Can I edit my .htaccess to write some WorldPress URL's (custom rewrites)?

So here's the problem: We don't like the fact that WordPress doesn't allow duplicate slugs, even for sub categories meaning we cannot have urls like:
product-1/guides
product-1/articles
product-2/guides
product-2/articles
That's very annoying! One solution we are considering is setting up our slugs like this:
product-1/product-1-guides
product-1/product-1-articles
product-2/product-2-guides
product-2/product-2-articles
But in our htaccess - can we use it to pick up such urls and rewrite them as prettier urls which have the product name removed from the sub folder? We don't mind hard coding these as we'll only ever have 5-10 products on the site.
This would keep the WordPress install happy with unique slugs, but the SEO tick in the box with better looking urls.
I just need a hand with the syntax please?
EDIT 1:
After looking at the WordPress Rewrite API, I'm failing to get anywhere with what I think is a really simple test. I have the following code in my functions.php which is running as I tested an echo, but no rewriting is taking place?
add_action( 'init', 'productRewrites' );
function productRewrites() {
add_rewrite_rule('^wordpress/james?','index.php?author_name=jwilson','top');
}
Nothing happens when I hit:
mysite.com/wordpress/james
Edit 2:
Cool I realise I now have to click save each time. The problem I now have is the following does not work not when I use $matches[1] - it only works if I hard code the author_name value (to jwilson for example):
function productRewrites() {
add_rewrite_rule(
"writer/([^/]+)/?",
"index.php?author_name=$matches[1]",
"top");
}
When I use $matches[1] it just returns everything! So clearly isn't using ([^/]+) in the url?!
you have to reset permalink structure
in order to do that, move to Settings -> Permalinks and press Save changes button

drupal 7 views block and contextual filter not working

I'm trying to set a contextual filter for a block type views but when I preview it, it returns nothing... More specifically when I try the same view as a page the Contextual filter is working fine and filtering the content but when I try the view as a block nothing is returned although the "Provide default value" is set as "raw value from url". Any idea what might be the problem? By the way I tried the solution here but it's still not working https://drupal.stackexchange.com/questions/13868/drupal-7-views-contextual-filters-with-page-blocks
When using views as blocks you need to enable ajax for the filters to work specially if its exposes.
go to advanced -> other -> and enable ajax and see it it works.
cheers,
Vishal
i ran into a similar situation: i was using content title as the contextual filter for a page, but when i tried to use the same filter for a block, the block doesn't show up. when i set the filter for the block (just the block) to content nid and set the default value to 'content id from url' it worked like a charm EVEN THOUGH THE CONTENT ID IS NOT IN THE PATH ALIAS. weird.
This might help someone...
I had the default view set correctly (in my case: raw url -> /part 2/, tick path alias) and the validation criteria set correctly (taxonomy term -> tick correct content type -> term name converted to id) but I was passing a third argument from my views_embed_view function call:
<?php print views_embed_view('recommended_documents', 'three', **$node->id**); ?>
I believe the arguments from the third onwards become the contextual filters values that are checked against, which we're looking to override with the raw URL.
The solution was to re-install drupal, no idea why, clearing the cache wasn't helping.

Resources