Wordpress - How can I access the custom post archive in browser? - php

This question may sound silly but it's really been giving me headaches. I created a custom post type name services and I also created a file name archive-services.php in the root of my theme folder in which I created a loop so that only the custom posts in services can be displayed. I didn't create any taxonomy since I won't be using them.
My permalinks are as follows: /%category%/%postname%/ so I'd expect that when accesing www.mydomain.com/services to see the archive page created.
Can you please tell me what am I doing wrong?

Related

How to change the 'Projects' permalink to the Category of the post in Wordpress

I would like to change the permalinks for projects to use the specific post's parent category name. Is this possible? I have come across a few tutorials via Google, though none seem specific to this cause.
I am currently using the Wordpress Projects section for Events and a Menu (restaurant). I would like the URLs associated with the posts in each of those categories to be /events/post-name and /menu/post-name
From:
www.website.com/projects/post-name
To:
www.website.com/events/post-name
www.website.com/menu/post-name
The Yoast SEO plugin can help you for doing this kind of URL manipulation.
Also, it seems you need to create Custom Post Types for your different kinds of contents. In your case, you can create an Events post type and a Menu post type.
There are several plugins available to help you with Custom Post Types, for exemple: Custom Post Type UI, Toolset Types...
And this one: post-type-switcher can be useful if you want to transfer your existing content in a newly created Post Type.
Hope it will help

Wordpress - Custom post type posts not using single.php

I have just upgraded to 4.7.3 and have an issue with my custom post types.
The posts were displaying fine until the upgrade, and I’m not sure how to fix this.
They all now use the index.php file instead of single.php, which isn’t right. My static / list pages all work fine, just the custom posts.
Please help. My PHP isn’t the greatest. I have tried deactivating plugins and it’s still not working.
Thanks.
To display single page of custom post type you need to create new 'single.php' file with appending your custom post type name in last with the new file.
For example, if your custom post type is 'book' then you need to create new file with name,
single-book.php
and save your permalink structure again.
Hope this might be work for you.
You can copy the single.php of the default WordPress folder and make it useable for your CPT. Check this link of Codex.
https://codex.wordpress.org/Post_Type_Templates

Custom Post Types not showing correct archive template

I have a few custom post types on my site:
lydbok
live
bidragsyter
The post types are set up using this code.
The lydbok post type have been working good on it's on. But when I created the other custom post types I ran into a problem when creating the archive-{post-type}.php templates. It seems that WordPress is using archive-lydbok.php even though I've added the archive templates for the other post types as well.
I now have these archive-templates in my themes folder(all files with just the file name inside, no code):
archive-lydbok.php
archive-live.php
archive-bidragsyter.php
archive.php
But when I visit mysite.com/?post_type=live or mysite.com/?post_type=bidragsyter WordPress is showing the archive-lydbok.php template instead of their respective templates. If i delete archive-lydbok.php the same URLs are showing the archive.php file. Not their archive-{post-type}.php template.
I have tried updating the permalinks inside of WordPress admin, as well as deleting the .htaccess and flushing rewrites using flush_rewrite_rules(); — but I'm still experiencing the same result.
It's worth mentioning that I created the lydbok post type using Pods a few months earlier, but deleted the plugin to use PHP code instead. Not sure if that have anything to do with it? The Pods plugin is completly removed.
This has happened to me on several occasions, but mostly its solved by permalink update. Once i also had to rename a custom post type to make it work.
Try removing the lydbok post type code from your functions. And see if the rest of the post types follow the their corresponding archive page. If it works then you should rename your custom post type "lydbok" to something else.

WordPress archive-custom.php page not working

I am new in WordPress.
I have a custom post type and from that custom post type, one post will show in home page, and below that post there is a link. When visitors will click on that link, it will take them in a page where all posts of that custom post type will show with pagination.
What I have done so far.
- Created custom post type.
Called one post in home page.( Upto that it's working fine. )
Created a archive-custom.php template.
But couldn't solve that link. Php the permalink doesn't work.
Also if I try to access the archive page by mysite.com/archive-custom.php no post shows there.
Search in Google, stackoverflow, wordpress codex . But unfortunately ended up with no result.
Any suggestions on how to solve this
Better way to develop archive page for a custome postype is, copy the code from archive.php (of coarse from your current theme folder) and paste it on newly created page "archive-yourpostype.php" . Then start tweaking on the code.
From your other post, your post type is called latestnews. When you look at the Template Hierarchy (which BTW you have to read thouroughly), you can create a custom archive page for your custom poist type. For this to work, has_archive have to be set to true when registering your post type.
Now, lets look at what is happening. You have a custom archive page, arhive-custom.php. When you directly access
mysite.com/archive-custom.php
It will fail, as it is wrong permalink structure.
Also, wordpress will look for the custom post type custom, which will outright fail, because that post type does not exist.
If your post type is called latestnews, then your archive page should be called archive-latestnews.php

How do I create a custom archive page that my client can edit?

Hi there Wordpress answers communnity
- I've created a custom post type.
I have set has_archive as true and understand I could also set it to has_archive => 'ctp'.
I also know that if I name a template file archive-cpt.php Wordpress will use this template for my cpt.
This is okay for some situations. But I'd like my client to be able to go to an editing page, like default posts and pages in the admin area.
I have thought about making the archive-cpt.php a template that can be called in a default page. Making that page the archive.
Am I on the right track? I'd really like to do this with the most up to date Wordpress method.
Thanks in advance for any guidance
custom-post-types customization templates archives
How do I create a custom archive page that my client can edit?
The Solution
I created a page called archive-mycustomposttype.php which wordpress automatically uses as the archive page for your custom post type, if it exists.
I then created a new section in wordpress's customizer and added controls with text, textarea and image settings.
I called the saved values via in the archive-customposttype.php template.
I hope this helps

Categories