WordPress.org

Ready to get started?Download WordPress

Forums

Displaying post list AND a selected post together on the same page (14 posts)

  1. Nessdufrat
    Member
    Posted 1 year ago #

    Hi!
    I'm in the process of creating a new wordpress theme. My last experience with wordpress was four years ago, so lots of things have changed.
    I tried googling the question, but it's quite difficult to find something as specific as that using terms that reoccur far too often like post list and article...
    What I need to do is actually quite complicated (in my mind, at least). I need to have a post list (with the first few lines of the articles) for a category in particular (this is fine, I'm pretty sure I can guess how to do it). BUT : I need to be able to display the article I select on a div next to the list, without having the list changing or switching to the article I selected...
    So, basically, imagine the list of articles on the left, and when you select one, the list doesn't change and the article opens right by the list's side. Of course, selecting another article in the list will have the new article displayed on the side too.
    For the moment, I'm not asking for help (I might soon ^^), I'd just like to know if something like that is doable or if my idea is totally crazy... (I'm not talking about a category, I want to display both the index.php (or is it category.php?) and single.php together on one page)
    Thanks for all advice! I'm basing my design on it, so I'd really like to know if it's doable before starting coding a theme.

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    I think you're going to need to look at a jQuery based solution for this.

  3. Nessdufrat
    Member
    Posted 1 year ago #

    Arrgh... I love php, but I don't know a thing about jQuery... I was hoping I could do something like a loop with php :/

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    You can't get a Loop to dynamically update the page without also refreshing the page.

  5. Nessdufrat
    Member
    Posted 1 year ago #

    Oh, it's alright to refresh the page. I don't need to display it on hover, I need to display the article when somebody clicks on the title.

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    Ahh! In that case, all you need is a modified single.php template file. The standard Loop would display the chosen post's content on one side and then the list of available posts would be generated by a secondary Loop on the other. You could use get_posts() or WP_Query() for this secondary Loop although, personally, I'd suggest getting to grips with the latter. Despite the slightly off-putting Codex page, if you read down, it's actually pretty straightforward.

    You might also want to read up on multiple Loops.

    HTH

  7. Nessdufrat
    Member
    Posted 1 year ago #

    Ok, thanks ! I was going for something like that, but I wasn't sure it could be done, so I wanted to know it was possible before starting anything :)
    The jQuery might be cool too, it would have been to simply mouse hover something and get the content on the side? (I'm not planning to try it, it would be like killing a moskito with a bazooka for what I need, but I'm just curious since you mentionned it)
    I'll have to get acquainted with the codex pages again, there were my bestfriend when I was coding my various websites a long time ago... I discovered recently that all the hard work with the php tweaks I had to do for my old websites is now useless since it's been integrated into wordpress :)

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    It's all eminently do-able using just PHP & WP. And if you find any Codex pages that don't make sense, just holler. :-)

  9. Nessdufrat
    Member
    Posted 1 year ago #

    Oh, actually, something else... My website will have horizontal scrolling, so the point was to first have a list of categories, click on a category and have the post list, and click on the post title and have the post.
    Could I (should I ?) modify index.php and integrate everything into it? Or should I have single.php as my website index page?

  10. esmi
    Forum Moderator
    Posted 1 year ago #

    You can't use single.php as a front page. You'd have to use index.php or front-page.php.

  11. Nessdufrat
    Member
    Posted 1 year ago #

    Ok, I'm realizing I probably can't do what I need in php, I hadn't thought about some stuff, and since I'm going to use mootools to have a slide effect when somebody clicks on a post title to get to the part on the website where the post is showing, it won't work if the page needs to be refreshed.
    Could you give me some pointers about the jquery based solution? That would be awesome...

  12. Nessdufrat
    Member
    Posted 1 year ago #

    Oh, I thought about something :
    Could I, with javascript, refresh the various loops on click? And maybe send in a variable, so that if somebody clicks on category 2, it could replace the variable to display the child categories of this category (and refreshing the child category loop and post loop at the same time), and then, same thing with the child category, clicking on the post title would refresh the post loop?
    I don't usually mix php and javascript and I don't even know if it's possible to pass variables from javascript to php, but in case it can be done, it could be a way to do what I'm after.

  13. Nessdufrat
    Member
    Posted 1 year ago #

    I found something to start with here : http://wordpress.stackexchange.com/questions/35849/using-ajax-on-categories-and-wordpress-loops

    But I can't get it to work. The category list displays fine (no surprise here since it's a basic wordpress function), but the script part does nothing and I don't get any post list...

    I can't find out what's wrong with the code, as I'm not used to ajax stuff...

  14. Nessdufrat
    Member
    Posted 1 year ago #

    I found another tutorial and tried to follow it, but it wouldn't work. Same thing as before, the script part does nothing...
    Is there something to activate in order to use AJAX with WordPress?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.