As to filter the exhibition of the news, and to do for example:
To exhibit the last 5 news of the category X.
or to exhibit the 5 read of a certain author. I would like to know as I can make that, just a basic example or a link of the official site of the wordpress that show those tags because I didn’t find.
This should do it:
<?php query_posts('category_name=mycategory&showposts=5'); ?> <?php while (have_posts()) : the_post(); ?> <!-- Do stuff... --> <?php endwhile;?>
mycategoryto the actual category name. I think that same code should work using
author_nametoo. Just put it in one of your page templates and see how it works. This is all part of your loop:
And something related:
Now I only have more a doubt. I tested that in the index.php of my theme, but now I returned to the normal and me wanted to create a new page for my theme to place that code and to work. In fact, me until I already created this other file (index_sub.php) that exhibits the last 5 publications of a specific category. But as I do to activate, to open, to visualize that page? Which link that I should use?
I tried: http://www.mysite.com/wordpress/wp-content/themes/my_theme/index_sub.php but it didn’t work, it exhibits the mistake:
Fatal error: Call to undefined function get_header() in /home/.paste/mysite/mysite.com/wordpress/wp-content/themes/my_theme/index_sub.php on line 1
Line 1: <?php get_header(); ?>
But as I can do to exhibit a page different from the ones that they are common in the templates: category.php, index.php, single.php…
If I created the page test_new.php or index_sub.php and sending for the paste of my theme, as I do to visualize her?
If you create a page in WordPress (Write >> Write Page), there’s a spot to choose the page template (right side of the screen, “Page Template”). That’s where you’d choose the template for that page and how you’d get that template to show up on your site. I *think* that’s what you want to know.
I thank for the answer, but it is not exactly that that I want to do, besides I already created pages for the system, but in those pages doesn’t have as inserting code php, includes…
I created a file for the template, if I publish as index.php or single.php he is exhibited in the site, in the initial page or in the reading of the contents, respectively. But if I leave the name of the file with test.php or index_sub.php I don’t know that link I should use to exhibit that page, since I don’t want you show it in the main page and yes to leave a link for they visualize that page.
If I didn’t go clear in to explanation, inform that will try to explain better. 😉
But if I leave the name of the file with test.php or index_sub.php I don’t know that link I should use to exhibit that page
OK, I will repeat it clearly: YOU CAN NOT LINK TO IT. End of story. WordPress doesn’t work like that.
Rather learn how WP works instead of trying to “violate” it 🙂
Excuse, but I am not trying to violate that, I just wanted to exhibit, to show that page.
Because I think am not getting to explain right that I want… But this very day, I lowered a theme that had the files single1.php, single2.php, sidebar_a.php, sidebar_b.php and each one had a different appearance and in that template that there is for sign several thus, all those pages can be included and shown for the user. But I didn’t get to see as that theme he/she does to exhibit pages different from the pattern of the wordpress, that is just the single.php for example.
And in my case, I also made a different page, and wanted to exhibit it, and that I want to know that I should configure to show the page index_new.php, that works in a correct way when I publish in the paste of the theme as index.php, but I want that the two are so much available the index.php (current) as the index_new.php (that is the new page that I did), and that new one I left to exhibit the last 5 publications of a specific category and for being of a special theme I used some different images in the layout of the page.
Because I think am not getting to explain right that I want
No, I understand perfectly what you say… the problem is YOU are not listening to what is said to you: you are obsessed with your preconception of how WP “should” work, and you don’t want to accept that it works differently and you don’t even try to learn about it.
Template_Hierarchy – this is how the template files in the theme work.
Thank you, but in spite of me already to have read some pages, I will probably have to read another to understand as accomplishing this that I want, but unhappily I will use other system that I already tested and I consider more practical for such task (CuteNews), that it simply allows to insert an include for the configuration file and to use the tags of the system, without needing of themes, could use the files in any directory.
It is possible yes to do exactly that you want… the problem is that in fact, you are totally obsessed to execute that action of the way that you want, but to do that, in the wordpress it is in another way, but it is also very simple:
In the page that you made the new layout, that you called index_sub.php or test.php, insert in the top:
<?php /* Template Name: New Page */ ?>
Now, enter in its panel of administration of the wordpress, and create a new page, placing the title that to want, for example, “blog” and if it is using permanlinks the url it will be: http://www.yoursite.com/blog
In this new page doesn’t write anything, just select in the template (to the right) “New Page”, that the new layout that you created was. Then you will notice that that new page that you did can be visualized, getting its objective.
Besides the tsguitar had already said that, but I think you didn’t understand or didn’t know as using.
For more details, it is very important to read at least the basic part of the documentation, the way that the system works and for the templates:
Creating your own Page Templates
Thank you very much! Now it is working of the way that I needed. I ask excuse the whole ones for my “obsession”, in fact I didn’t pay attention in other alternatives that could be done to arrive to the same result.
But I am still with a problem. When I click in the links of this page that it is with the different template, when will read the news she opens in the standard layout, and there I made new single.php, saved as single_sub.php, but I didn’t get to do with that the news are open in this new template. Could anybody give more that help?
This problem I had not noticed in the templates, because it is a resource that I don’t use. But with certainty should have a form to open the news in the new single.php that you created to maintain the new layout in the reading of the publications.
But I don’t really know about that. It will be necessary somebody more expert in the wordpress to inform you or to try to read in the documentation on that, to search for on topics that speak about that, but it should be simple thing. If I find I place the code here.
That’s not a valid template file name. WordPress cannot recognize it as an “alternative” single.php.
WordPress cannot recognize it as an “alternative” single.php.
Ok, but then as I could solve the problem that I mentioned?
When I click in the links of this page that it is with the different template, when will read the news she opens in the standard layout, but I didn’t get to do with that the news are open in this new template.
I looked for that in the documentation, I already read several parts, but I didn’t get to correct that.
- The topic ‘To filter posts exhibition’ is closed to new replies.