Forums

[resolved] how to include posts of specific cat in a page? (25 posts)

  1. antishape
    Member
    Posted 9 months ago #

    Is it possible to include a category's posts (even if the cat doesn't show up because I excluded it, but status is published) in a page? I'd like to add the posts of specific cat into a page to be display (headlines only) but doesn't know how to do it. Tried different html sitemaps but they didn't do well and the same goes to different php execute plugins to include get_post code from the wp codex. Any other way? Maybe conditional tags? If so, where do I need to include the conditional tags and how do I solve my problem mentioned above.

  2. Digital Raindrops
    Member
    Posted 9 months ago #

    If it is a page then a page template would work, or a copy of index.php with a query, which theme are you using?

    Example with images:
    WordPress Twenty Eleven One Category Page, where the page slug = category slug, like category News (slug=news) Page News (slug=news), page content can be written with the posts below.

    page-category.php
    http://pastebin.com/h59nXctx

    The content or loop image removed(content-onecat.php)
    http://pastebin.com/cwAJxhTc

    HTH

    David

  3. antishape
    Member
    Posted 9 months ago #

    It's the Wire Magazine theme. Don't how to do both of the suggestions.

  4. Digital Raindrops
    Member
    Posted 9 months ago #

    Is it a free one, if so add a link!

  5. antishape
    Member
    Posted 9 months ago #

  6. vjpo
    Member
    Posted 9 months ago #

  7. antishape
    Member
    Posted 9 months ago #

    Do I need backticks or without them? Both versions doesn't function anyway.

    Used this:
    [catlist category=2419 orderby=post_title order=ASC post_type=posts post_status=published]

    Put this code while html mode or in visual?

  8. Digital Raindrops
    Member
    Posted 9 months ago #

    Try this template page, if you have ftp, copy the raw code and save it in a file page-onecat.php.
    http://pastebin.com/UKzpZ6BX

    Upload it to the themes folder via ftp.

    if the category was sports, create a new page and make the page slug the same as the category slug, add the page to the menu, then apply the template to the page and you have a page with titles and excerpts.

    It was created from the index.php and page.php of the Wire Magazine theme, and has been tested.

    HTH

    David

  9. antishape
    Member
    Posted 9 months ago #

    Thanks, looks good. But how do I add cat-id and how to display it in a browser? Couldn't find any sections where I can add a id or cat name or a slug. Nor do I know how to embed it in my page which already exists and should display this.
    Both, cat and page (the one with posts of the specific cat) are named people. That's also the slug of both, cat and page.

  10. Digital Raindrops
    Member
    Posted 9 months ago #

    You can start with an empty page if you do not want a leader text block.

    Admin > Pages > Pages find the page 'People' and quick edit, there is a dropdown option "Page Template" select One Category and publish.

    The page has two sections the first is the page content so you can add static text which is optional.

    The second section will display the Title and Excerpt for any posts that are in a category with the same slug page slug = people and category slug = people

    Let us know if you find it ok.

    HTH

    David

  11. antishape
    Member
    Posted 9 months ago #

    Done. But nothing appears.

    Both cat name and page have the same name (People) and slug (people) and the cat contains one post to display but nothing happens.
    http://www.newssquared.de/people/

    Any idea?

  12. Digital Raindrops
    Member
    Posted 9 months ago #

    Admin > Pages > Pages find the page 'People' and quick edit, there is a dropdown option "Page Template" select the template 'One Category' and publish.

  13. antishape
    Member
    Posted 9 months ago #

    That's what I did.

  14. Digital Raindrops
    Member
    Posted 9 months ago #

    That is strange, I have tested it here and it works fine.

    http://digitalraindrops.net/images/wire-magazine.png

    have you got a category with many posts, just change the page slug to match and test again?

    David

  15. antishape
    Member
    Posted 9 months ago #

    Checked it again with a category including many posts. It's fine.

    Don't know what's up with the category. Maybe it's something with the cat title and page title, should I change? Guess it depends only on the slugs so it won't matter?

  16. antishape
    Member
    Posted 9 months ago #

    And, by the way does it matter if the both page and category aren't visible for visitors but still published? They're just excluded from the menu.

  17. Digital Raindrops
    Member
    Posted 9 months ago #

    It does not look at the page title only the slugs which WordPress creates in the right format.

    The only thing I can think of is if you had two categories with the same names, but I am sure that WordPress will append a numeric value.

    Sports
    -People slug = people
    Movies
    -People slug = people-1
    Fashion
    -People slug = people-2

    post_name is the slug and title is what you see, so it should work, one post should also still show.

    $pageslug = $post->post_name;
    $catslug = get_category_by_slug($pageslug);

    And, by the way does it matter if the both page and category aren't visible for visitors but still published? They're just excluded from the menu.

    I use the code on my own website, and only select a few featured categories I want so it should be fine.

    HTH

    David

  18. antishape
    Member
    Posted 9 months ago #

    If it's the same slug WP stops me from creating another one, I need to add a number manually. But I can't see a solution for my problem. Maybe more posts?

  19. Digital Raindrops
    Member
    Posted 9 months ago #

    Run the category people direct and you get, "Sorry, but there aren't any posts in the People category yet."

    So it looks like any posts have not been assigned to the people category.

    HTH

    David

  20. antishape
    Member
    Posted 9 months ago #

    I see. The problem was a plugin named Ultimate Category Excluder. Thanks a lot. Runs fine.

  21. Digital Raindrops
    Member
    Posted 9 months ago #

    Often the way!

    Can you mark this topic as resolved please.

    David

  22. antishape
    Member
    Posted 9 months ago #

    Sure, mark it right away.

    One more thing if you don't mind: order by post title possible?

  23. Digital Raindrops
    Member
    Posted 9 months ago #

    With wp_query() there are loads of arguments, worth a look at all the options.

    Order by Title ASC

    $args=array(
        'cat' => $catid,
        'paged' => $paged,
        'orderby' => 'title',
    );

    Order by Title Desc

    $args=array(
        'cat' => $catid,
        'paged' => $paged,
        'orderby' => 'title',
        'order' => 'DESC',
    );

    HTH

    David

  24. antishape
    Member
    Posted 9 months ago #

    Thanks a lot!

  25. antishape
    Member
    Posted 9 months ago #

Reply

You must log in to post.

About this Topic