• hutruk

    (@hutruk)


    Hi!

    I would like to display the list of my posts in an accordion on a single page. Not some content inside a post, but the post itself with the title as the heading and the post’s content inside the collapsible part. And each new post should add a new collapsible. What would be the best way to do that?

    Thanks in advance!

    <img src=”https://i.imgur.com/ckws0oe.jpg&#8221; title=”Hosted by imgur.com” />

Viewing 12 replies - 1 through 12 (of 12 total)
  • Piyush

    (@piyushpesw)

    you can use this one and put the post code on this HTML

    https://jqueryui.com/accordion/

    Thread Starter hutruk

    (@hutruk)

    Thanks for the quick answer!

    I used the following code, but it doesn’t work for me yet… As an absolute PHP beginner, I might be overlooking something…:

    <?php if ( have_posts() ) : while ( have_posts() ) : ?>
    <h3><?php the_title(); ?></h3>
      <div>
        <p>
        <?php the_content(); ?>
        </p>
      </div>
    <?php endwhile; else: ?>
    <p>Something went wrong.</p>
    <?php endif; ?>
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Which theme are you using?

    Thread Starter hutruk

    (@hutruk)

    I’m using a custom theme prepared especially for that particular website.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    It’s not clear what exactly you need help with after Piyush provided the link to the jQuery accordion method.

    Thread Starter hutruk

    (@hutruk)

    The problem is with the right syntax. I’m not quite clear on how to place the elements of the loop together with the jquery accordion syntax…

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I would like to display the list of my posts in an accordion on a single page.

    So at the moment do you have your list of your posts? Can you provide us with a sample bit of HTML of that list’s output?

    Thread Starter hutruk

    (@hutruk)

    Right now with the code I posted above I get the following output:

    <div id="content-text-top"><div id="accordion">
     <h3>Portfolio</h3>
      <div>
        <p>
            </p>
      </div>
     <h3>Portfolio</h3>
      <div>
        <p>
            </p>
      </div>
     <h3>Portfolio</h3>
      <div>
        <p>
            </p>
      </div>
     <h3>Portfolio</h3>
      <div>
        <p>
            </p>
      </div>
     <h3>Portfolio</h3>
      <div>
        <p>
            </p>
      </div>
     <h3>Portfolio</h3>
      <div>
        <p>
            </p>
      </div>
     <h3>Portfolio</h3>
      <div>
        <p>
            </p>
      </div>
     <h3>Portfolio</h3>
      <div>
        <p>
            </p>
      </div>
     <h3>Portfolio</h3>
      <div>
        <p>
            </p>
      </div>
     <h3>Portfolio</h3>
      <div>
        <p>
            </p>
      </div>
     <h3>Portfolio/h3>
      <div>

    Portfolio is the title of the page itself and that list goes on forever if I don’t stop the page from loading…

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Okay so you already have the HTML structure for the jQuery, you don’t need to modify that.

    Thread Starter hutruk

    (@hutruk)

    No, the problem seems to be with the loop syntax I posted above…

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Why if it’s outputting the right HTML structure for the accordion method?

    Thread Starter hutruk

    (@hutruk)

    Yes, but it is outputting it indefinately and it’s outputting just the name of the page it’s placed on, instead of displaying the title and content of my posts…

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Display posts in an accordion’ is closed to new replies.