I am developing a website where I am required to have individual pages for every different posts. I have to put 8 posts in eight different styles and properties, that is why I need those pages.
For example as we know for each page template we can make something like
page-templateone.php
Like that I want something similar for posts, just for example:
post-numberone.php
You can create a following php file in your theme folder
single-{post_type}-{post_slug}.php
For example, you have a post with a slug very-important-post. To have a template for this post alone, you need to create a file called single-post-very-important-post.php
If you'd like to be able to select template from the post editing screen, in 4.7 post type templates became available. Read more here
If you'd like to be able to do it in the older verion, take a look here
Related
I am trying to create a custom archive template for my categories. I have a parent category called
member-resources, which is a parent category for multiple other categories.
I do not want to access these categories by /category/member-resources.
According to wordpress documentation for template hierarchy, I need to create archive-member-resources.php and change the php code to display as needed.
However this template is not the one being rendered(archive.php is always being rendered), and if I try to access it by entering /member-resources I get a 404..
What am I missing ? thanks
[EDIT]
Excuse my wordpress skills as I have only been working with it for about a month..
I asked this question for a very simple reason. I worked on a project, in which I ended up with a massive archive.php file with alot of conditional logic such as :
if( is_category('events') ), render a side menu
if( is_category('news') ) , render something else
if( is_category('member-resources') ) render pagination
This is just an example, but I wanted to highlight that with different categories, I might want to call a completely different archive template( if at all possible ), rather than having a large file which is not very maintainable..
If this cannot be done, please provide me with a solution, so that on my next project, I wouldn't run into this problem again.
You should not use any type of archive page (archive.php, category.php, taxonomy.php etc) as a listings/index page. That is not what archive pages are intended for. Also, the template hierarchy specific to archive-xxx.php is for custom post types, not categories.
The main query on any archive page is quite specific and should not be tampered with on template level. It totally destroys pagination and common logic within the main query.
You should make use of a page template. Just simply copy your page.php, rename it to page-xxx.php, add the necessary page header and modify it as needed
For further reading
Page Templates
WP_Query
New to Drupal. Installed it, set Bartik theme as default, created a few pages with a menu. Now I would like to do something like this:
where the pictures with descriptions link to either other pages or articles. Each of them should have custom size.
What is the simplest way to do it?
For the testing I have created 4 articles on my home page, but obviously they sit one on top of each other. The same happens when I add blocks.
There is not better option to this than to install and use Views module. You can achieve exactly what you want using the nice UI it provides.
You need Views if
You like the default front page view, but you find you want to sort it differently.
You like the default taxonomy/term view, but you find you want to sort it differently; for example, alphabetically.
You use /tracker, but you want to restrict it to posts of a certain type.
You like the idea of the 'article' module, but it doesn't display articles the way you like.
You want a way to display a block with the 5 most recent posts of some particular type.
You want to provide 'unread forum posts'.
You want a monthly archive similar to the typical Movable Type/Wordpress archives that displays a link to the in the form of "Month, YYYY (X)" where X is the number of posts that month, and displays them in a block. The links lead to a simple list of posts for that month.
P.S - Views module is the most used and installed module in Drupal, hence, it will be a part of Drupal 8 core.
For a project of mine I need to define an alternative template for single posts.
To be more specific I need each post to be displayed as usual when the website is browsed but I need to create different single pages reachable from different URL to create a sort of a mini-website for each post.
(I'm actually using the WooCommerce plugin and what I need to do is to create a mini-website for each product. This needs to be something "outside" from the main website, with a complete different graphic template and is going to be reachable through a QR-code).
Hope it makes a bit of sense.
Thanks for your advices and/or suggestions.
Angelo
I think the easiest way to do that is by registering a custom post type for the special posts that get this special "single.php" template. Then, you can simply write a new single template titled post-[custom post_type].php. Any post you register of this type will use that template.
OR...
If you don't actually need them to be posts, it's even easier if you publish them as pages. By default, pages let you assign a specific page template in the edit screen. So you could make any number of custom templates. Just make sure you add the special header:
/* Template Name: Custom Page */
...so WP knows it's a page template.
Hello I am trying to generate a Drupal node which would be similar to a feed page generated by views module. I need to generate an xml feed, so I would not want to show the regular drupal template that is showed up on every node. I am trying to understand how the views for feed works as I want to display my page in a similar fashion, without the drupal template. Any suggestions would be great.
In Drupal you can theme any individual page to be completely different than the default template. So, if you have a node, let's say the url is "node/14", you can create a new template file called "page-node-14.tpl.php" in your theme folder. In this template you can add any html/xml markup you need. Also, for that specific node you should also create a "node-14.tpl.php" to theme that node's content.
If you want to display more nodes on a page, something like "taxonomy/term/3" (here you can find all nodes tagged with the term with the ID 3), you have to create a "page-taxonomy-term-3.tpl.php" template in your theme folder. To theme every node from one particular content type, you should create a "node-news.tpl.php" (this is for news node types) in your theme folder.
Please keep in mind that these template suggestions are for Drupal 6. In Drupal 7, the template name changed from "node-news.tpl.php" to "node--news.tpl.php"
I have to create a simple company blog within drupal-6. That means there should be only one single blog each user can post into.
What i have done so far is to create a custom content Type (blog) and a view that displays teasers of the recent blog entries with links to the full blog post.
Now i have to create a Tag-Cloud for this blog.
I created a taxonomy vocabulary for this "blog" content type and set the settings to Tags (Terms are created by users when submitting posts by typing a comma separated list.)
I also installed the Tagadelic Module and created a tag cloud with it, that works great and it displays all the Tags i entered when creating new blog entires.
But now to my problems:
First: If i click on an entry in this tag-cloud the default Taxonomy_term view is used to display the resulting blog entries. Thats bad because i would like to have it displayed the same way as in the view i already defined to show the blogs. Is there a way to use my view to display the results of the tag-cloud?
Second: On my view, below each blog-teaser should be a link to related blog entries (the ones that share the same terms). I do not have a clue how to do that.
is this even possible with the setting i have now or should i maybe take a whole other approach to create that company blog with tag clouds and related blog entries?
You should be able to solve both problems pretty easily, while keeping your current approach:
Take a look at your views list ('admin/build/views/list'). You should see a view called 'taxonomy_term (default)', which is usually disabled by default. This is an optional override of the built in taxonomy term page. You can enable this and configure it to look like the blog view you created.
Alternatively, you could leave that one disabled, but add another display of type 'page' to your already existing blog view, and configure that as an override to the built in taxonomy term. For this you'll need to set the path of that display to 'taxonomy/term/%' and adjust the display to use the term id argument as a filter (look at the above override for how this works).
You could also do it the other way round - use the default taxonomy_term override view, configure its output according to your blog view needs, and add another display for your recent blog entries to that. After this, delete your own blog view and use the new display of the taxonomy term override instead.