• Is there any function that returns the content of a specific article (just the content, no comments, no “page” around it) by the article’s title or at least by ID? I can’t find anything in the documented API.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter joh

    (@joh)

    OK, if someone has an answer, please provide it ??
    After looking at what actually happens when you point a browser at index.php?name=my-great-page I’m quite sure that there is no such function, documented or not. wp-blog-header.php handles this and goes with no further fuss to building a database query. I fear I have to write my own get_content_by_page_name() function. Well, shouldn’t be that hard.

    You can certainly delete everything but the_content in the loop if that is all you want.

    Thread Starter joh

    (@joh)

    Hmm, don’t see that… What I want to do is being able to create, edit and maintain pieces of HTML as normal articles and then insert them into the page (outside the loop) with a function that just grabs the HTML content of an article out of the database. I don’t want to use this instead of the normal way the blog looks and works but additionally to it.
    So that I can for example have a text-block in a sidebar that actually is a short article ‘sidebar-block’ in the database by using <?php get_content_by_name('sidebar-block'); ?> in the desired place in index.php.
    And what I’m actually about is putting together the code for a CMS plugin. Having more pieces of the page (and things like menus) generated from articles pulled out of the database is quite a nice thing to have for that…

    Thread Starter joh

    (@joh)

    Ahh! Thank you very much. This looks much simpler than what I would have written…

    I’ve used Kafkaesqui’s get-a-post function and it’s a nice solution. However, I’ve run into a problem with it. I used it to make a ‘sticky’ article which always appears at the top of the page. The problem is that my sticky contains a <more> link and when this is clicked I get the ‘sticky’ article as expected plus the another copy beneath it because I’ve asked for more. Is there any way I could stop this hall of mirrors?

    Absolutely brilliant! alphaoide. Thank you for the incredibly speedy response.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Get (single) article content by post title?’ is closed to new replies.