WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Chunks of text around the main text in a page (6 posts)

  1. Dunkkan
    Member
    Posted 5 years ago #

    Hi folks,

    I'd like to show several chunks of text beeing displayed around the main text in a Page. That text, if possible, should be managed through the posts/pages editor, just to avoid to go inside the html every time.

    Somebody knows the php call, or similar, to gain something like that (playing with the ID's maybe)?

    Cheers.

  2. @mercime
    Volunteer Moderator
    Posted 5 years ago #

    You have to clearer than "chunks of text" that you want to be displayed.

  3. Dunkkan
    Member
    Posted 5 years ago #

    Thanks mercime for reply,

    I was thinking in several pages, two or three, with just a little of text written in it (two paragraphs), modified every week, which can join a page with the 'main' text, a long article for exemple.

    I hope I'm understanding your request.

    What I need is write them in the Editor, instead of in the html.

  4. @mercime
    Volunteer Moderator
    Posted 5 years ago #

    By page, do you mean a couple or so WordPress Pages inserted beside the latest Post in the front page? It can be done but you would have to change or add some HTML/PHP codes in customized front page for it to work.

  5. Dunkkan
    Member
    Posted 5 years ago #

    Ok I get something.

    1- You create a php file. A page Template. What it means it starts like this:

    <?php
    /*
    Template Name: Chuck Norris
    */
    ?>

    You can change the template's name, or let 'Chuck Norris', as you want.
    Then you write some code, for a post which will be displayed first:

    <?php rewind_posts(); ?>
    <?php
     $posts = get_posts('category=14');
     foreach($posts as $post) :
        setup_postdata($post);
     ?>
     <?php the_content(); ?>
     <?php endforeach; ?>

    As I want to display my category 14, where I just have 1 post, I write 14 in the adequated place below.

    Then, we go for the second post to display:

    <?php
     $posts = get_posts('category=15');
     foreach($posts as $post) :
        setup_postdata($post);
     ?>
     <?php the_content(); ?>
     <?php endforeach; ?>

    The same operation, with category 15.

    Like this you can get an initially EMPTY page, without its own, normal loop, but full of FOREIGN posts.
    Then, playing with html/css you can build a very cool home page (you can set it as a homepage in the Ad panel), with a main article, and some complementary articles, all of them build as posts in the Post Editor.

    Enough for what I wanted.

    I'm not able to understand properly the 'rewind' function which is in the first post, and which theoretically helps to regain the possibility to display a second loop. I was not able to set at the same time a normal loop in there, so the call for a rewind function is maybe not necessary here, because the only posts I'm building comes from 'somewhere else'. More techie, depurated info at http://codex.wordpress.org/Template_Tags/get_posts#Parameters

    I hope this helps somebody. My code can be full of horrors even in the shortest line, so be carefull.

  6. Dunkkan
    Member
    Posted 5 years ago #

    I forgot to mention in my case I delete the 'title' tag before 'the content' tag, because don't need it :P

Topic Closed

This topic has been closed to new replies.

About this Topic