Wordpress Page Hierarchy - wordpress

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.

Related

Map a Static Page to Custom Post Type archive page

I've registered a custom post type named portfolio. It's archive enabled, so I can visit it's archive page by visiting http://example.com/portfolio/ permalink.
Now, I want to create a static page with any given slug e.g. courses and I want to resolve this static page ID (as slug may change) to archive-portfolio.php page mentioned above.
Additionally, I also want to use that static page to be able to set as front page (just like any other static page) without losing it's ability to map to portfolio archive page.
How do I achieve this functionality?
Note: I want to implement this functionality in a commercial theme, so, any solution suggested must work out of the box i.e. without forcing end-user to deal with the file strucutre.

Wordpress- Creating an archive template

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

Wordpress template page for custom posts

I have a custom post type (that I'm using on a template page), the custom post type is called 'Headerhome'.
When I post say a gallery there I'm trying to get it to redirect to 'single-Headerhome.php', yet it always just goes to 'single.php'.
The name of the custom post type itself is arbitrary, the name of the templage page it's on is 'home'.
I'm really confused, I'm not the best at WP yet so when something simple like this doesn't work I have no idea how to fix it, even after pouring over the codex for an hour.
The name of the custom post type itself is arbitrary, the name of the templage page it's on is 'home'.
Reading this implies that you have a home.php file in your theme, which would automatically display as your front page of your site. This may not be what you desire? More on this here: http://codex.wordpress.org/Creating_a_Static_Front_Page
An example of a custom post type might be an Event. The Event might have custom fields associated with it, like Location, Date, Time, Description. We would probably want new Events to show up on our front page, but also would want to create a custom theme file so when a user clicks on an Event from the home page to view the Event then the Event page shows our Date, Time, Location, Description, etc. We would then create a single-event.php to do this and put in any custom code their.
So (another example), a custom post type of Fruit would have an associated theme file of single-fruit.php. If their is no single-fruit.php then Wordpress will use single.php as the default theme file to display. More on this here: http://codex.wordpress.org/Post_Types#Template_Files
Hope this helps set you in the right direction.

WordPress: Showing posts by categories/tags on the index page

Is it possible to show posts by categories/tags on the index page instead of taking the user to the tag.php and category.php pages?
For example, when the user clicks the 'Uncategorized' category, I would like all the Uncategorized posts to replace the list of posts already there on the index page.
I've been trying to find out if anyone has done this but I've had no luck. I'd really appreciate it if someone could give me a link to somewhere that tells me how to go about doing this or lets me know how to change the code to get this to work.
This can be done. I can not recall a page that has done it but I do know it would require you creating your own custom page template.
http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates is a good place to start learning how the page templates are created.
Some additional links
http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query
http://wordpress.org/support/topic/tag-archive-from-a-single-category-is-this-possible?replies=34

Limit wordpress posts loop to continue onto another page

Theres a site i did that on the home page, i created kind of like a news box type
of thing which is what the client wanted...
the posts bit im using to limit the posts on the index page is
query_posts('posts_per_page=4');
Now, this limits my posts to "4" or whatever number i want etc, when the user clicks on the
"news" page button, it takes them to a page which has the full posts loop without the
query_posts('posts_per_page=4'); which essentially shows them all the posts.
Now the problem is that, this person is posting A LOT now and the page now has a bunch of posts one after the other.
Is there a way to limit these to any number (that i choose) and show the rest of the posts on another page???
So essentially something that says
filter out 20 messages/excerpts for example, BUT after 20 show a "next" page or something like that?
is that possible? Because as it stands now, by years end this ONE page will have hundreds of posts.
ive looked around but not sure exactly what im looking for. This one came close (here on SO)
Wordpress loop show limit posts
And although its similar, i need a way to limit the posts on the page AND continue them on another page so that one page doesnt hold ALL the posts.
Thanks in advanced.
The homepage is controlled by index.php or a template file used by a page which you can set up to be your homepage at Settings > Reading.
You must check your index.php file or the template file used the page from the homepage.
If your queries in the code are not including any "posts per page" arguments, you can control this numbers from Settings > Reading.
There is also a plugin which can help you:
http://wordpress.org/extend/plugins/custom-post-limits/
Now, clicking on news page, you must check if that is a page or a category listing?
If it's a page, then it is handled by page.php or an attached/used template for it. Again, the code is important, how the queries are written. It it's a category listing, then the category.php is handling that page.
Pay attention for the template files are using each every page/post and learn this: http://codex.wordpress.org/Class_Reference/WP_Query
Good luck! :)
http://codex.wordpress.org/Settings_Reading_Screen
In the settings you can set a default max limit of how many posts per page.

Resources