• chrisatlemon

    (@chrisatlemon)


    Hi again,

    many questions today, I’m working on several blogs at the same time! ??

    How can I create an index page say “index_news.php” which displays only the latest entries from one category (news) but nothing else? This can be out of the loop completely and an entirely independent page…

    Thanks for any tips!

    Chris

Viewing 6 replies - 1 through 6 (of 6 total)
  • moshu

    (@moshu)

    Doesn’t the category view do that?
    And what d you mean “out of the loop”?

    abecks555

    (@abecks555)

    I have a similar related question, on my website I want the standard index page to display posts from only one category. How can I do this? It currently displays all of the categories posts. https://mindset.tk

    This might help solve chris’s question as well.

    moshu

    (@moshu)

    abecks555,
    yours is a totally different question.
    (First of all stop using that .tk domain – a lot things will not work in WP with that.)

    You can use a plugin Plugins.
    You can modify The_Loop.
    You can use the query_posts tag.
    And you can use Google to find more ?? – see the stickynpost on the main page of the forum: How to search…

    Thread Starter chrisatlemon

    (@chrisatlemon)

    Tanks for the reply moshu,

    yes category view does that, but I aksed on another thread how I could make category view display as a page with a .php extension and got no reply, so I guess either no-one knows or it’s complicated.

    So with some lateral thinking I thought: maybe I can create a page and this page only shows entries from one category, and create another page which only shows entries from another category. But I want them to be pages, something.php.

    I thought this could be easy to do, just like I can take stuff out of the sidebar, make it display only certain categories in the cat_list etc and call it sidebar2.php, which I can then include on any other page on my site.

    By out of the loop I meant that it does not have to work within the logic of the blog. It should just produce a list of entries of one category, nothing else. Maybe I didn’t express myself properly ??

    Cheers

    Chris

    moshu

    (@moshu)

    If not in the blog:
    – put on the top of your whatever.php file, before everything else, this:
    <?php
    require('./path-to-your-blog/wp-blog-header.php');
    ?>

    – having that you can use any WP function, including The_Loop in that file
    – for excluding categories or to have only one shown… see the links I gave above: Loop, query_posts etc.

    Thread Starter chrisatlemon

    (@chrisatlemon)

    Ah, very useful, thank you very much! While you wrote that I found another solution, but it may be somewhat less elegant, I will try both!

    What I found was to vcreate a new page called index2.php and put:

    <?php
    /* Short and sweet */
    define(‘WP_USE_THEMES’, false);
    require(‘./wp-blog-header.php’);
    ?>

    <?php
    if (is_home()) {
    query_posts(“cat=3”);
    }
    ?>

    …at the top of my page and then use whatever I need of the index page (title, content, comments etc.) below. This would show only items of category 3.

    I can then include this page via php include anyweher on my site…

    Your solution may be more elegant as I can do without the include an just have the functions referenced driectly!

    Thanks for the help, much appreciated!

    Chris

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘index.php which displays posts from 1 category only’ is closed to new replies.