wordpress custom archive page type - wordpress

i'm starting with wordpress (from a drupal background) and trying to figure out how to create a new "menu" or url pattern. not quite sure what the lingo is in wordpress so im having a little trouble searching online for it.
the current archive allows you to sort by: /post/date/2010/06
what i'm trying to do is extend the archive functionality to include a "day" as well.
ie. /post/date/2010/06/22
i dont mind creating a new page type for this purpose such as /archive/YYYY/MM/DD or something like that.
not sure where to begin with matching the "url pattern" to the "url handler" function or template.

I ended up using:
<ul><?php wp_get_archives('type=daily'); ?></ul>
It gave me an archival list of links which point directly to the pages I needed.
The archive already supported filtering by day, so I just needed to find a way to access it.
The url pattern is /post/yyyy/mm/dd
If anyone is interested in generating a link directly to that page, use:
<?php echo get_day_link(2010, 6, 20); ?>

Wordpress can customize the style of permalinks you use on the Settings/Permalinks tab of your administrative page. It sounds like you want something like /%year%/%monthnum%/%day%/%postname%, which should allow you to group by year, year/month, and year/month/date.

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

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.

Modifying the menu navigation to include the domain

Some background if you want to see why I'm doing what I'm doing:
I have a client who wanted a new blog done with Wordpress on a separate subdomain. Their existing website is on Drupal, which I have had 0 experience with prior to this. They have a pretty extensive navigation on that site (multiple levels), so rather than create duplicates of nav menus that would need updated on both wordpress and drupal, I am using YQL to pull in the whole navigation onto the Wordpress website. I know this isn't great for SEO, but at this point I'm not worried about that.
The issue I have is that all of the links on the Drupal website do not include the http://domain.com so that none of the links work on the blog site, because they're going to relative pages on that subdomain that don't exist.
So in summary, what I'm trying to accomplish:
I need each href that Drupal is generating to begin with 'http://domain.com'. Currently they just start with '/pagename'. I have no clue what Drupal version the site is on nor on how to find it, sorry. The site is using Drupal's Nice Menu plugin as well. I've been digging through the files for a couple of hours now, and can't figure out where I need to make the change. Please help! Thanks
Edit: dobeerman mentioned using custom_url_rewrite_outbound to settings.php. This seems to accomplish close to what I want. I tried adding this to the end of settings.php:
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
global $user;
$path = 'http://www.reillypainting.com/'.$path;
}
However, the end result of an href in the menu becomes this example:
href="/http%3A/%252Fwww.reillypainting.com/services/sell/rent-your-house"
So the other code generating Drupal's menu is trying to escape the :// and it's also still adding a / to the beginning of the href. Anyone know how to avoid this?
Drupal has function custom_url_rewrite_outbound you can add to settings.php
Use this code:
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
$options['absolute'] = 1;
}

Change management in WordPress

I have a beginner question. What is the best way to address the change management issues in WordPress? I have an all-pages WordPress installation. Suppose name of some event or an entity changes from A to B, then I have to go to all the pages to make that change. Is there any better way of doing it? Like externalization or something.
Or the way similar to how WordPress handle blog name using bloginfo() function. You change blog name at one place and it is reflected everywhere.
Thanks,
Paras
If a URL on your site changes, it is always wise to leave a redirect to the new page. This will help your visitors and search engines. If you create redirects, it doesn't matter too much if you still have a link to the old address in one of your posts. There will probably be a plugin for this, but I don't know which one.
If you really want to keep all links pointing to the latest version, you could replace them with shortcodes that are evaluated to the real URL. <a href="[linkto postid=123]"> would then result in <a href="/2010/08/05/some-post">. I think this is doable, but I don't know whether a plugin already exists for this.
You can also use this technique to replace short snippets, like your company name. The Shortcode API is really easy:
// [company_name]
function replace_company_name($atts) {
return "My Awesome Company";
}
add_shortcode('company_name', 'replace_company_name');
// More generic
// [replace r='company_name']
// [replace r='company_motto']
function do_replacement($atts) {
$replacements = array(
'company_name' => 'My Awesome Company',
'company_motto' => 'A Company so Awesome even you would want to work here!',
);
return $replacements[$atts['r']];
}
add_shortcode('replace', 'do_replacement');
You can hardcode the strings in your plugin code, or you could create a Wordpress options page where users can add and edit new shortcodes.

Wordpress Plugin to Generate non-numeric slug / permalink for posts without titles? (1 post)

I've been looking for this all over, and simply cannot find it.
I have a blog that has no titles in its blog posts, but I'd like, for various usability reasons, to have the permalinks use the first few words from entries that do not have titles as the permalink slug.
ie, if the post on sample.com/blog is
Title: (no title)
Content: Ten Easy Ways to Lose Weight
The permalink could be sample.com/blog/ten-easy-ways-to-lose-weight.
Are there any plugins that do this? For the life of me, I cannot find one. (xposted to WP support, but no one is responding)
You could enter in titles, and then not display them in your view template.
I doubt there's anything like this already built for wordpress. To get your blog to do this, you have to write a plugin that does the following:
Generates the slug while checking
for uniqueness should you ever start
more than one entry with the same words
Processes URL requests to recognize slug permalinks and then updates the query step to locate the correct post in the database. This might involve a new db table of slugs (which would also help with the uniqueness issue)
In short, WP is designed to retrieve almost everything by keys, and to support slugs like this you'd have to create a new key type.
btw: if anything is retrieved by IDs (keys), it is technically not a permalink. so, wordpress probably fails in providing true permalinks.
ps: it's not that difficult to write an handler/dispatcher that would parse URL and takle out the unique permalink and then match it to the DB by the string (not by the key!).
something like:
$url=$_SERVER["REQUEST_URI"];
echo 'URL called: ',$url,'<br />';
$dispatchfile=$dispatcher->Dispatch($url);
if ($dispatchfile)
{
echo 'launching ',$dispatchfile,' inclusion<br />';
require($dispatchfile);
}
else
{
echo 'dispatcher failed to find module, will check physical file<br />';
if (file_exists($url)) echo 'dispatcher found physical file<br />';
else echo 'nada, throw 404!';
}
You can get a permalink redirect plugin from
http://scott.yang.id.au/code/permalink-redirect/
Works fine with WP2.71
It takes the Title and auto-creates a slug from that so you would have to manually enter the slug you wanted for each page if you have a Blank Title.
You should be able to hack Scott's PHP file (it is one page only) to look up the page code and select a portion of it to use as a slug though.
In addition, I solve incorrect page requests using a .htaccess rewrite file to bring up the index page upon an incorrect page request.
Download a copy of my rewrite file here
https://oulixes.com/htaccess_example.zip
Unzip the txt file and rename as .htaccess and upload into your root directory
Hope this helps!
Cheers,
Billy

Resources