WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] To filter posts exhibition (19 posts)

  1. newboxters
    Member
    Posted 6 years ago #

    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.

  2. tsguitar
    Member
    Posted 6 years ago #

    This should do it:

    <?php query_posts('category_name=mycategory&showposts=5'); ?>
    
      <?php while (have_posts()) : the_post(); ?>
        <!-- Do stuff... -->
      <?php endwhile;?>

    Just change mycategory to the actual category name. I think that same code should work using author_name too. Just put it in one of your page templates and see how it works. This is all part of your loop:
    http://codex.wordpress.org/The_Loop

    And something related:
    http://codex.wordpress.org/User:JamesVL/query_posts

  3. newboxters
    Member
    Posted 6 years ago #

    Ok, worked.
    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(); ?>

  4. moshu
    Member
    Posted 6 years ago #

    You cannot link to template files directly. It just doesn't work.

    Stepping_into_Templates
    Theme_Development

  5. newboxters
    Member
    Posted 6 years ago #

    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?

  6. tsguitar
    Member
    Posted 6 years ago #

    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.

  7. newboxters
    Member
    Posted 6 years ago #

    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. ;)

  8. moshu
    Member
    Posted 6 years ago #

    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 :)

  9. newboxters
    Member
    Posted 6 years ago #

    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.

  10. moshu
    Member
    Posted 6 years ago #

    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.

  11. newboxters
    Member
    Posted 6 years ago #

    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.

  12. julious
    Member
    Posted 6 years ago #

    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

  13. newboxters
    Member
    Posted 6 years ago #

    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?

  14. julious
    Member
    Posted 6 years ago #

    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.

  15. moshu
    Member
    Posted 6 years ago #

    single_sub.php
    That's not a valid template file name. WordPress cannot recognize it as an "alternative" single.php.

  16. newboxters
    Member
    Posted 6 years ago #

    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.

  17. julious
    Member
    Posted 6 years ago #

    Links for research:
    http://wordpress.org/support/topic/27073?replies=29#post-168009
    http://codex.wordpress.org/Template_Tags/in_category#Use_OUTSIDE_The_Loop

    With every respect to the moderator, it is possible yes to do "alternatives" for the single.php independent of the name, and he knows about that. The subject is that are not happening complete information because you are not reading the documentation.

    I will explain to you quickly, because it is something very simple, doesn't need plugin, in spite of an advanced part to be considered in the wordpress by editing the codes, it is the basic of the programming PHP.

    Insert in top of the single.php:

    <?php
    $post = $wp_query->post;
    if ( in_category('1') ) {
    include(TEMPLATEPATH . '/single1.php');
    }
    elseif ( in_category('2') ) {
    include(TEMPLATEPATH . '/single_sub.php');
    }
    else {
    include(TEMPLATEPATH . '/single.php');
    }
    ?>

    ( in_category('1') ), where 1 is id category.

    In that way, if the user is reading a content that it was published in the category of id 1, then he will open single1.php (a page with the specific layout). If the content is of the category of id 2, then will open the content in single_sub.php (with the layout of its blog for example), and if it is a content published then in any other category will open the content in single.php (the standard layout of its site).

    Then, a clue, remove a time to read most of the documentation of the wordpress, navigate among doubts solved at the forum, look for in the web on its doubt or problem and later if you have not really found, then post here.

    Another important clue, is to know at least the basic part of programming PHP and database MySQL, because if you want to manipulate the wordpress that uses that programming language completely, you will have very more easiness tends that basic knowledge, and the time that you spent for learning that it will be worthwhile to accomplish modifications that you will do well faster.

  18. moshu
    Member
    Posted 6 years ago #

    The OP never mentioned he wanted single templates by category:
    http://guff.szub.net/2005/07/21/post-templates-by-category/

  19. newboxters
    Member
    Posted 6 years ago #

    Thank you julious! It was quite so that I needed. I tested and it worked. Thank you again, it was a very important help for me to conclude my site.

    moshu, thank you also for its small clues, but in fact they didn't help me a lot.

    Resolved topic.

Topic Closed

This topic has been closed to new replies.

About this Topic