Section Hierarchy in Hugo - permalinks

I'm trying to build a structure for permalinks in Hugo + blogdown where a post will have the permalink structure of
websitename/category/slug
Not sure how to do this because I've set the config.toml permalink structure to
[permalinks]
posts = "/:section/:slug"
and I place the post (an .md file) into a folder, which is a category, underneath the posts file but I get a url similar to websitename/posts/category/slug... when what I really want is websitename/category/slug.
I was hoping to make the category the section, but not have "post" in the URL.
I'm still trying to figure out where to place the _index.md file but have not been very successful. Any help would be appreciated.

The permalink is set on a per section basis. The sections are the first-level directories under content, not under content/posts/.
So, if you want the permalink to be websitename/category/slug, arrange category directories(or sections by the Hugo term) like this:
content
├── category1
│   └── 2015-01-04-first-post.md
├── category2
│   └── 2015-01-27-dear-diary.md
├── _index.md
├── page
│   └── about.md
└── post
├── 2017-03-07-bigimg-sample.md
└── 2017-03-20-photoswipe-gallery-sample.md
and set
[permalinks]
category1 = "/:section/:slug"
category2 = "/:section/:slug"
page = "/:section/:slug"
post = "/:section/:slug"
in your config.yaml
Source: https://gohugo.io/content-management/urls/#permalinks

Related

Woocommerce: can't use woocommerce template

I just installed Woocommerce plugin on my Wordpress site and create my own custom theme. My theme structure should be like this:
.
├── index.php
├── style.css
├── functions.php
Now, when I tried to access, /cart route, it still load blank page (which i presume my homepage), and I can't load Woocommerce template that resides in ~/wp-content/plugins/woocommerce/template/cart/. I've read the docs here, but it only explains about template overriding.
Now, how do I load ~/wp-content/plugins/woocommerce/template/cart/ template, when i access /cart route on my site ?
I also tried to change my cart page attribute template on dashboard->pages->cart, but i can only set it as default template with no other options.
What you have so far is the basic wp custom theme structure.
In order to add Woocommerce support to your theme add this function to your functions.php file
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
Then if you want to have a custom cart page for example and not the default Woocommerce cart layout you have to add a folder Woocommerce in your theme root folder and and as a subfolder the part you want to override form the Woocommerce plugin template file.
Wordpress custom theme structure with Woocommerce support:
.
├── index.php
├── style.css
├── functions.php
├── woocommerce
├── cart
├── cart.php
If you are looking to use the default WooCommerce cart page, you will have to add what is called a 'shortcode' into one of your pages. The Wordpress editor will do the rest to set up the page and its functionality.
For the cart page, all you have to do is add a this text somewhere on the page that you would like to act as the cart: [woocommerce_cart].
If you would also like to use a checkout page, the shortcode for that is [woocommerce_checkout].
If you do either of these, you will also want to change the WooCommerce plugin's default cart and checkout pages to your pages. This can be done in 'Dashboard > WooCommerce > Settings > Advanced' under the 'Page setup' header.
This page may be a helpful resource if you have continued interest in using WooCommerce shortcodes in your site: https://docs.woocommerce.com/document/woocommerce-shortcodes/.

How do I post some introductory paragraphs on the main page of my blogdown site?

My initial menu for my blogdown site is taken directly from the blogdown book.
[[menu.main]]
name = "Home"
url = "/"
weight = 1
[[menu.main]]
name = "About"
url = "/about/"
weight = 2
[[menu.main]]
name = "GitHub"
url = "https://github.com/rstudio/blogdown"
weight = 3
[[menu.main]]
name = "CV"
url = "/vitae/"
weight = 4
[[menu.main]]
name = "Twitter"
url = "https://twitter.com/rstudio"
weight = 5
The index of my site automatically populates with any posts I add via Addins > New Post. If I alter my index.Rmd file in my main project directory (shown below) no changes occur on my front landing 'homepage'.
├── archetypes/
├── content/
├── data/
├── layouts/
├── public/
├── ...
├── config.toml
├── index.Rmd
└── my-website.Rproj
My index.Rmd file looks like this, although my website won't publish my intended paragraph on my main 'homepage'.
---
site: blogdown:::blogdown_site
---
# Intended first paragraph
Hi. Thank you for visiting my website... more words... etc
To further complicate matters, there is no _index.md file in my content/ directory. Could this be the issue? I'd like to post some introductory paragraphs before all my posts appear on the main page (homepage) of my blogdown website.
Yes, you need to create _index.md under content/. Then the content of _index.md will be displayed on your homepage.
There was a minor issue with the hugo-lithium theme, which I just fixed on Github. In the old version, if _index.md is not empty, the list of posts will not be displayed. Now both the content and the list of posts will be displayed. If that is not what you want, you can certainly revert my change in layouts/_default/list.html.

Add a image on a cshtml

I've an WebSite written in Asp.Net.
I wish to add a image on the login page (a cshtml file).
I tried this :
<img src="#Url.Content("~/Content/logo.png")" alt="Answer logo" />
But it doesn't works, the image is not displayed.
Is there specific settings to add on the "Content" folder or on the "logo.png" file ?
My project structure :
Project
|
|- Content
|- logo.png
|- View
|- Auth
|- LogIn.cshtml

How to make get_header() call a custom header file located in a sub-folder of the theme?

From a PHP template file located in a sub-folder of my WP theme folder (my_theme/subfolder/my_file.php) I want to use get_header() and call a custom header-new.php located in the same sub-folder.
Instead, get_header(header-new) loads header.php located in my theme root folder. How to fix that problem?
You are correct to use get_header() function. However, as per documentation you should pass the name of the custom header in the specific format - only the part that comes between 'header-' and '.php'. E.g. for the custom header in the file:
header-custom.php
you should use:
get_header('custom');
But that's not all. It is important to remember that the custom header file should be placed in 1 or 2 specific directories, depending on whether you're working on parent or child theme:
Parent theme: you should place it either in the same directory as the page template or the 'root' theme directory (specifically the same directory where your style.css is)
Child theme: you have to place it in the 'root' child theme directory
get_header() function calls locate_template() function, which searches for the custom header file in those 2 directories. If it doesn't find the file, it defaults to 'header.php'.
you can use :
get_template_part('header-new.php');
reference here: >https://developer.wordpress.org/reference/functions/get_template_part/

Wordpress template list not showing up in posts

I'm facing a very common problem with Wordpress, I don't see the list of my templates in the post edit page. There are tons of posts about this here but I haven't found the solution to my problem in any of them.
I basically have this in my theme directory: index.php, page.php, header.php, functions.php, sidebar.php, style.css
in page.php and index.php, I have:
/*
Template Name: HOME
*/
and
/*
Template Name: PAGE
*/
What I've already tried:
- switched back to the original Wordpress theme and back to mine
- made sure permission 755 was attributed to folder
- copied a working file from another theme and inserted my code into it
- completely logged out and came back
but nothing worked, I still don't see the list of templates for my theme while for official themes, I do see the list of page templates.
Any suggestions?
Thanks
Laurent
You cannot use index.php or page.php as a Page Template, because those files are reserved for other templates of a theme.
As the Page Template reference states:
Name your template file so you can easily identify its Template Name, e.g., filename my-custom-page.php for template name "My Custom Page". Some coders group their templates with a filename prefix, such as page_my-custom-page.php (Don't use page- prefix as WordPress will interpret the file as a specialized page template.)
For information on Theme file-naming conventions and filenames you cannot use, see reserved Theme filenames.

Resources