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
Related
I'm not a super-experienced Wordpress guy, but I generally know what I'm doing, and have been programming for years.
I'm in the middle of building a fairly simple Wordpress site, but lots of posts will be added in the future by the client.
It suddenly dawned on me that all my posts are static, so if changes in design are needed they will need to be applied manually across many pages.
I've searched Google but to no avail. What I need is a plugin or method that allows me to have templates for my posts, into which the unique content for each page are added. Then, if design changes are needed, I simply edit the template and the design will change instantly across all the pages using this template.
I've found plugins which seem to offer post templates, but all they seem to do is create a new post with a pre-made design, but do not make it possible to make changes to that design which are reflected across all the posts that use that template. Maybe I'm missing something simple here, as I can't be the only WP author who wants to achieve this?
I'm not talking about dynamic content. ie I have no need to pull constantly updated data like weather or prices from an API. The content is hand-written for each page, but I would like to separate it from the design, so if design changes are needed they can be made only once from some kind of post template manager, and not individually on each page.
Actually, I'm already using the simple post-snippets plugin, and I realise that I could use this or something similar to achieve my aim, but I don't think this would be very user-friendly for non-technical authors. Instead, it would be ideal if I had a set of custom fields under each post which the authors filled in, and the content was then taken from there and inserted in the page's template.
In principle you should be able to change the design just using CSS selectors. Of course that may have its limitations but there is never a design that fits it all.
For bigger changes you will need to change the WordPress template.
Ok, after some research and poking around, this is what I've come up with.
Install the 'Advanced Custom Fields' and 'Custom Post Templates' plugins , although neither are strictly necessary.
Create a group of custom fields which defines the unique data (URL, media selector etc) for each post.
Most importantly, create a new custom post template following the instructions for the 'Custom Post Templates' plugin. In this template remove the line that outputs the post content (the_content()), and replace it with code that outputs all the shortcodes or whatever for this page type, with placeholders string replaced with the values of the custom variables for that post. Then (in my case) I do something like do_shortcode($page_template) to correctly output the correct content for that page.
I create a new post, leaving the content field completely empty, and filling in the custom field's values as required. Also, you must choose the post template, so it matches the new custom template you create.
$v=get_post_custom_values("image_url")[0];//gets the id of the post which contains the image
$image_url = wp_get_attachment_image_src($v, 'medium')[0]; //get the image (URL?) from the reference
$page_template='[one_third last="no" spacing="yes" background_color="" background_image="" background_repeat="no-repeat" background_position="left top" border_size="2px" border_color="#eaeaea" border_style="solid" padding="20px" class="" id=""][imageframe lightbox="no" style_type="none" bordercolor="" bordersize="0px" borderradius="0" stylecolor="" align="none" link="" linktarget="_self" animation_type="0" animation_direction="down" animation_speed="0.1" class="" id=""] <img src="#image_url#" alt="" />[/imageframe][fusion_text]Email Me | Website[/fusion_text][/one_third][two_third last="yes" spacing="yes" background_color="" background_image="" background_repeat="no-repeat" background_position="left top" border_size="0px" border_color="" border_style="" padding="" class="" id=""][fusion_text]#main_text_html#[/fusion_text][/two_third]';
$page_template=str_replace ( "#image_url#" , $image_url , $page_template );
echo do_shortcode($page_template);
The code above contains the page template hard-coded into the $page_template variable, but it could also be loaded by referencing the id of the post which is acting as the template.
This code currently only inserts the correct image URL. Once it's finished it will also insert the personal email link, website link, and main text.
I have a page that has a single category applied to it, for this example, "Self Help Books".
I want to put a place on content type that display a "view all [insert category here]" that links to that category listing page. I was hoping I could do something like:
<a href=%taxonomyLink:books--self-help-books%>view all%taxonomy:books%</a>
and it would pull in the category for anything using that content type. I'm using the panels modules so I had planned on placing this in a panel the content type was using. Is any of this possible?
I thought about creating a block and placing that in a panel in the panels module.
(also, if you can't tell, I'm pretty fresh to Drupal.)
you can use simple drupal api function to achieve that.
first you will need to load needed taxonomy term (lets say that 123 is taxonomy term ID)
then build the link
here is the code:
$term = taxonomy_term_load(123);
$link = l($term->name, 'taxonomy/term/' . $term->tid);
you can also find more about l() here https://api.drupal.org/api/drupal/includes%21common.inc/function/l/7
This Drupal docs page lists several modules that assist in displaying related content, via a few different methods.
As of now, the most stable 7.x compatible terms-based module appears to be Similar by Terms.
There are ways to achieve this without installing an additional module, but this will satisfy your requirements as-is.
You don't need to write code for this. If you using panels .. Find a way to put a right relationship in context for needed taxonomy term, after that you will have all the needed tokens (%placeholders) to build your content.
I have the following page on a site in development:
http://telamon.com.s137737.gridserver.com/media/press/
I want to do some stuff outside the loop, so I created page-press.php based on my understanding of the WP page hierarchy (http://codex.wordpress.org/Template_Hierarchy). It isn't working. I've reset permalinks as well. This isn't the first time I've had problems here and I just ended up creating a template, but this should work shouldn't it?
Yes it is true that the hierarchy should work like that, but for it to work you need the following to be true:
It needs to be in the Single mood
The page need to be a static page
You can't apply any other custom template on the page
The slug of the page needs to be "press"
If all of these are true, then it should work. If not, then check the following, find the id of the page and create a page-$ID.php and check if that works. See if you end up in the page.php template file, or if you end up in index.php try to use var_dump on a few variables like is_single() and so on.
EDIT:
Single mood is when the page is listed by it's own, not in a list.
Static page means this is not a post, or a list view like archive or something like that
Custom template is when you create a page to be a specific "page template" available to choose from, when you edit you page (down right).
Slug is not the same as your title, nor you id. It's most likely a url friendly variation of your title.
I am little more than beginner PHP programmer and just recently started to use wordpress. Right now I have big theoretical problem:
How to display in wordpress list of Posts (yes, default posts, not custom post type) with different template (does not have to be completely different new template) defined by current URL?
I am using Wordpress 3.3.2 and trying to customise wonderfull graphene theme. Runing on Linux/apache with mod_rewrite
Example:
I have posts in my page, which are displaying in front-page, and I have also created a menu with post categories. I am using permalinks.
www.mypage.com <- this shows list of all posts
www.mypage.com/category/dslr/ <- this shows list of all posts in selected category
www.mypage.com/2012/06/12/mozem-auto-komentovat/ <- this one shows single post
That is completely OK, easy to understand, no problem.
Example here: http://portal.vip.sk/vyvoj/astro/en where "astro" is root folder for this test instalation.
What I want to do:
Create a button in main menu, which will point to:
www.mypage.com/different-list
And on that link I will see all queried posts from DB, but the design and query will be different. Please note that different-list is not defined anywhere, nowhere even in the taxonomy, so when i try to use that link i get 404 error. I also want to use different custom fields from DB in this special listing.
The reason for this construction is as follows:
I want to let users publish their posts, categorise them, fill in metadata for these posts etc. BUT I also want to show these user posts in different manner under different URL. In this list, the posts will be grouped by months (or other time interval), by categories and will use one meta (boolean true, false). And of course the layout of the page will be completely different.
Thank you for any advice
To create a page template, create a new blank php file and populate it as follows:
<?php
/**
* Template Name: The name of you page template
*/
?>
<?php get_header(); ?>
Your content, queries, and stuff.
<?php get_footer(); ?>
Then add a new page, select as template "The name of you page template" and voila.
For custom fields I suggest you to use the "More Fields" wordpress plugin found here: http://wordpress.org/extend/plugins/more-fields/
Good luck! :)
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.