WordPress.org

Forums

Displaying posts in pages (32 posts)

  1. jetlund
    Member
    Posted 10 years ago #

    Hi,

    Is there a way of displaying posts in pages. That is, in WP it is possible to setup "static" pages, and with a plugin I'm allowed to write php in the content area of a page. However doing simple copy-paste from the index page does not display any posts.

    My objective here is to have a single page for each category of posts in addition to an initial text on each page.

    Any suggestions?

  2. moshu
    Member
    Posted 10 years ago #

    You do not need any plugin to put "content" into your pages. Just use the Write Page admin panel.
    I don't really understand what are you after with the single Pages. Could you, please, re-phrase it?

  3. Minna
    Member
    Posted 10 years ago #

    If you mean that you'd like some sort of introduction to each category ("Posts about web design") and then the posts after it like in a regular archive, you could get the initial text for categories with <?php category_description(); ?> without having to make extra pages (the description is written in the Category's properties). For example this is what I do in Archive Template:
    <div id="intro">
    <?php if (is_category()) { ?>
    <h1><?php single_cat_title('',true); ?></h1>
    <?php echo category_description(); ?>
    <?php } ?>
    </div>

    (that goes before the if (have_posts()) etc. part)

  4. jetlund
    Member
    Posted 10 years ago #

    Sure,

    guess I was a bit difficult to understand...

    I want to display posts from a certain category on a single page, and posts from amother category from another page. Then secondly I will create (this I have done) a menu displaying all my pages...

    So it is not the pure content thats my problem - it is displaying posts on other pages than the main page

    hope I'm understandable :-)

  5. moshu
    Member
    Posted 10 years ago #

    By default displaying posts from a category WP uses the archive.php template. See Template Hierarchy.
    You can also create Category Templates for you categories:
    http://codex.wordpress.org/Category_Templates

  6. jetlund
    Member
    Posted 10 years ago #

    Sure I could use categories for this - but then the problem is the menu system. I would then like to have a main menu displaying all categories (easy) - but also a submenu displaying all subcategories in a certain category!

    In fact this would be easier since it goes hand in hand with my "MarsEdit". But I still haven't figured out how to display all subcategories when displaying a category....

  7. moshu
    Member
    Posted 10 years ago #

  8. jetlund
    Member
    Posted 10 years ago #

    OK, thanx for the input!
    It actually did help! However, for my needs, not completely!

    Thus, I still would like an answer to the following question (which is not meant philiosophically):

    ** Can I display dynamic content--such as posts--on a static page in wordpress?

  9. moshu
    Member
    Posted 10 years ago #

    Tricky question, LOL
    Despite their name the Pages actually are dynamic, since their content is stored in the DB.
    There is also a lot of info here in the forum if you do a search for "category template".

  10. Aife
    Member
    Posted 10 years ago #

    NO NO NO!!! He is just asking how do you put in the loop posts (wich are time dependent) inside a template page..

    From what I have gathered it is not possible. The loop will get the post as the page content.

    For example, I would like to create many a diferent view to index.php to my posts wich exists at same time as index.php... Or to acess the post list from a page...

    I would like someone to really clarify me on this situation...

  11. hesed2
    Member
    Posted 10 years ago #

    I've been thinking about doing something along these lines also, jetlund. I'm not sure if this will work, but here's what I would try:

    1) Make a copy of your index.php page and name it "something.php".
    2) Copy and paste the following code at the top of the something.php page you have just made:
    <?php
    /*
    Template Name: Whatever You Want To Call It
    */
    ?>

    This will allow you to use this as a template for your page(s).
    3) To restrict the post on something.php to one category, enter this code at the top of this page:
    <?php
    if (empty($_SERVER['QUERY_STRING'])) {
    $cat = 'numberofcategory';
    }

    /* Don't remove this line. */
    require('./wp-blog-header.php');
    ?>

    4) Create a new page in your admin section (Write>Write Page). On the Page Template: dropdown menu, select the template you just created ("Whatever You Want To Call It", in this example).

    Like I said, I'm not sure if it will work, but that's where I'd start. I hope that helps.

    You might find these links helpful as well:
    http://wordpress.org/support/topic/22853
    http://codex.wordpress.org/Pages

  12. hesed2
    Member
    Posted 10 years ago #

    Hmm, I just tried that myself and it doesn't work. As Aife said, the loop pulls the text you enter into the page content instead of posts from the category you want. I have no idea how to do it, then...I guess you'd have to find a way to distinguish between a "standard" post and the page content.

  13. Kafkaesqui

    Posted 10 years ago #

    Look here on setting up custom "multiple" loops:

    http://codex.wordpress.org/The_Loop#Multiple_Loops

    Specifically look at the info on how to use query_posts and WP_Query, which is what you're looking for to set up custom post queries in your Page template.

  14. Birdman
    Member
    Posted 10 years ago #

    I am trying to do something along the same lines as jetlund.
    Basically, I want to have a page which will display posts only meant for that page, and not visible in the normal post index. I have been trying a few things, and I will keep you posted on my progress.

  15. Aife
    Member
    Posted 10 years ago #

    What I have achieved is this:
    Copy the index.php to foo.php (for example) and then switching off the themes flag to false.

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

    Next you add the template you would like to use.
    From here you can call all the function available to the index template.
    The other pages (404.php and the like) will be from the themes but you will have a diferent take on the loop with posts.

  16. Aife
    Member
    Posted 10 years ago #

    You end not having posts in a page per se, but still can make a pseudo-page with posts.

  17. dolmarit
    Member
    Posted 10 years ago #

    Read the following topic complete on this page
    http://wordpress.org/support/topic/32639

    The topic is not completely the same but comes out a little bit the same to the question you have.
    In the last message from me I gave a solution referring to
    Plugin Name: Customizable Post Listings
    downloadable on
    http://www.coffee2code.com/wp-plugins/

    Maybe you also need a plugin for your home page all described in the codex.

    This plugin has really some wonderfull options you must play with the statements between %...% and change them in the original file use it as new YOURNAME.PHP and remove the references to plugin and use it as an include.

    With a few extra if and else statements you maybe can do some wonderfull things on your website.

    Or otherwise if to difficult make extra files with new replacements for the c2c references.

    The (1) I mentioned you always can replace for example in (5) to see 5 topics from one category etc...

    Also the category is easy to change.

    Whatever you like all honour ofcourse for the author of the PHP script.

    Hope it can help you somehow although there are much more solutions.

    Martin

  18. hesed2
    Member
    Posted 10 years ago #

    Ok, I've finally got this working over the weekend. Here's what you need to do:

    1) Make a copy of your index.php page and name it "something.php".

    2) Copy and paste the following code at the top of the something.php page you have just made:
    <?php
    /*
    Template Name: Whatever You Want To Call It
    */
    ?>
    This will allow you to use this as a template for your page(s).

    3) In this same something.php file, find this piece of code, near the bottom:
    <?php endif; ?>
    Just below this code, enter the following:
    <?php $my_query = new WP_Query('category_name=category_name_here&showposts=10'); ?> //edit this line accordingly

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

    4) Blow this enter the code to call your posts. In the case of the default template it would be something like this:
    <div class="post">
    <h2 id="post-<?php the_ID(); ?>"><a>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>

    <div class="entry">
    <?php the_content('Read the rest of this entry �'); ?>
    </div>

    <p class="postmetadata">Posted in <?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>

    <!--
    <?php trackback_rdf(); ?>
    -->
    </div>

    5) On the next line, enter this:
    <?php endwhile; ?>

    6) Go into your admin section and create a new page (Write>Write Page). On the Page Template: dropdown menu, select the template you just created ("Whatever You Want To Call It", in this example). Any content you enter here will show up at the top of the page.

    That's it. You may have to adjust the CSS for the posts, but that's fairly straightforward if you've made it this far.

  19. jmd4eva
    Member
    Posted 9 years ago #

    Can you not use a plugin to let php requests run in pages, then use it to bring up posts in a category? I would like to do this, but don't know how to go about it.

  20. altacivil
    Member
    Posted 9 years ago #

    The method mentioned two posts above mine works wonderfully... although you simply need to remove the "while: have_posts" (or whatever it says) and replace it with

    <?php $my_query = new WP_Query('category_name=category_name_here&showposts=10'); ?>

    ... you can leave the rest of your "index" file the way it is and things should work peachy for ya. At least that is how I implemented this on my site... I wanted to have a recipe page and instead of writing a seperate html page with all my recipes on it... I made posts to a recipe category and am displaying them on a seperate recie page... and not displaying them on the index page... seems to be working ok.

    Appologies for the rambling...

  21. altacivil
    Member
    Posted 9 years ago #

    I dont know if this has already been suggested but you could try using the query_posts() function as discussed in this thread:
    http://wordpress.org/support/topic/40733

    I am using it om my site and it works great... you just copy and remane your indes file and add the template info at the top. Then before your "the loop" you add the code for the query... tell it what category to allow (or disallow) and bam! you have what you are looking for.

    If you look at my site (http://gpetzold.swifthost.net) and go to my recipes page (not a lot on there yet) you can see that this works great! I post all my recipes as if they were normal blog entries (except I categorise them as, you guessed it, "recipes") and they are dealt with accordingly.

    Wow I sure do ramble dont i?

  22. dbasulto
    Member
    Posted 9 years ago #

    i did create a new file called cursos.php, and i edited the loop using the get_post code to only get the categori ID=37
    but if i try to access http://www.myhost.com/cursos.php it says file doesnt exist...any ideas? i guess this has something to do with .htaccess?

  23. jetlund
    Member
    Posted 9 years ago #

    Funny Thing - I started this thread in april 2005 and it is still alive!

    However, it is still unresolved! All sugestions are very much apreciated though.

    So lets try it again and see if anyone's got a better 'olution:

    1) Pages - such a nice feature of WP. Lets refer to them as pages. They are part of the database - which is important since they can be edited with editors like MarsEdit without having to think about uploading and downloading.

    2) PHP documents - are documents NOT pages in this thread!

    3) Posts well it is all about them. They are also a part of the DB and we'd like to display them by category, date and whatever - and we can.

    BUT here is the problem:

    I'd like to create a site using WP as a CMS. And I'd like to use posts to get a more dynamic feel to ever item that can be displayed from the menu. For the content part I'd like to use WP "Pages" and "Posts" only. For each category of posts I want to create a Page, and ditto for subcategories. So it is my Pages that displays the posts. Not a hacked/wacked copy of index.php. Still today it is not possible to do this. I now just wonde why!

  24. MichaelRondot
    Member
    Posted 9 years ago #

    Basic concept: http://wordpress.org/support/topic/50742#post-281862

    Just copy index.php -- save it, renamed as category-x.php where x is each category you want on a separate page.

    Set the value in the custom field on each page to call a different category category-x.php thru redirectify.

    Michael

  25. AndreSC
    Member
    Posted 9 years ago #

    jetlund:, when you reffer to a "a hacked/wacked copy of index.php" are you reffering to the index in the root of WordPress or The index.php in the relevant theme's page?

    Either way I think I can see where this is heading i.t.o. CMS application, manually creating 'template' pages per category is fine if you just need it for a special category or two, say recipies or jokes, but what if you need non-Wordpress or php savvy blog members to be able to create such cusomised 'dynamic-pages'... Me thinks there's a mean plugin idea in there.

  26. puddlejumper
    Member
    Posted 9 years ago #

    I have set up a "static" front page (using a plug-in already available) for a WordPress blog and then set up the category pages to display the description at the top and only the posts for that particular category. The categories actually look like page buttons on the bar (by changing the function call in the header.php in the templates). Take a look at the site: http://www.ctle.ngcsu.edu/rsinn/ Is this what you're looking for?

    WP already has the ability to display only posts from a single category by clicking on the category displayed in the sidebar; however, you can add a description of the category by creating a "category.php" page (originally using the index.php page which includes the loop), creating a desription for each category in the admin panel, and adding the following:


    <?php if ( is_category() ) : ?><br />
    <h2 id="category-name-header"><br />
    <?php echo $cache_categories[$cat]->cat_name ?> Category</h2><br />
    <?php add_filter('category_description', 'wpautop'); ?><br />
    <?php add_filter('category_description', 'wptexturize'); ?><br />
    <div id="category-description"><br />
    <?php echo category_description(); ?><br />
    </div><br />
    <?php endif; ?>

    This came from the documentation on WP under Category Templates. WP will first look for a specific category template, then a general category template (which is what I used), then archive, then index. I suggest you read through this section of the documentation: http://codex.wordpress.org/Category_Templates.
    It has a lot of useful information there.

    You will also need a plug-in that creates a "static" first page. This takes a page you've created with the page name slug of "home" and puts it first. You can find it at: http://www.semiologic.com/software/static-front/.
    Works beautifully!

    Hope this helps!

  27. jetlund
    Member
    Posted 9 years ago #

    AndreSC: I was talking changing the index.php for the root. I see your point and (MichaelRondot's point) that we could create one per category. But I've tried it at it doesn't help me since I get problems connecting with my editor...

    But your main point is right I want a CMS based on a Blog - why? - because external editors like ecto and marsedit really doesn't work to well with any CMS I know!

    There might be some need for a plugin! But me not goin to make it unless there is a shreeking demand and kudos to be gained:-)

    puddlejumper: I really had tried that plugin earlier. But in a earlier version. Haven't tried your suggested way of doing things, but I will!

    Gonna let you all know as soon as I have:-)

  28. jetlund
    Member
    Posted 9 years ago #

    I have to eat my words - almost: Putting together the solutions from AndreSC and puddlejumper made my day.

    I have got it working know - just like I've wanted for over a year. The key is just to do all the things that AndreSC and puddlejumper mentioned in their posts above. I am still working on streamlining the process so It's currently no good in me posting a finnished solution. However if anybodu really wants to know I'll post it later on!

  29. Russ Williams
    Member
    Posted 9 years ago #

    Exactly what I want to do. I have a site setup, with no connections to WP at all. The site exists in the top directory. Then in a subdirectory, I have WP installed. I want to use WP as a "News" script. That is, whenever someone creates a "Post" in WP, it is displayed on the index.php page of the "Static" site a directory above the WordPress installation. Then on this static index.php page of my "Static" site, it would show a brief summary of the Post and when you click on it, it would take you to http://www.yoursite.com/wordpress/?p=5 or the exact post. I have the Template in WordPress setup to look exactly like the rest of the site, so the user will have no clue that they are leaving the "Static" site and entering the "WP" site and it's own templates. Is this more or less the solution that worked for you jetlund?

  30. jetlund
    Member
    Posted 9 years ago #

    Not exactly what I had in mind - but it is something that went through my head as an extention to the site. I don't think I'll ever use WP for the dynamic part of my sites. It might seem backwards but I use the dymaic part of WP to display static content - it is not a BLOG.... I have a blogs also but these are user based and is a separate blog per user. This are handled as simply and powerfull as possible without the use of databases at all thsough a dynamic html page :-)

    I wrote "Not exa..." above, but of course I may (again) be wrong - easier to answer if I could see your site in action...

    And by the way - sorry for a delay in me answering your question, but after changing jobs (and thus computer) a great deal of my weekly "to-do's" have been lost:

Topic Closed

This topic has been closed to new replies.

About this Topic