Content Parts

Plugin version: 1.3
Requires WordPress version: 3.3.1
Tested up to WordPress version: 3.3.1
Download: Click here to download...

Description

This plugin allows you to split your editable content into multiple parts and display each part using template tags within your theme, allowing you to create complex content layouts.

It works in a similar way to how you split your content area into multiple pages…

Splitting your content into multiple parts

The plugin adds a new button to the rich text editor.

Clicking this button will insert a break to divide your content into multiple parts. The break will be define by a dotted line and tag.

In the HTML these dividers are defined by HTML comments so they degrade seamlessly if you deactivate the plugin – they don’t display to the user.

Adding template tags to your theme

To display the content parts you will need to add some template tags to your theme. Without adding tags the content will continue to display as normal using the the_content() template tag.

The Content Parts plugin has several template tags to display your content:

  • the_content_part( $page = 1, $args = null );
  • get_the_content_part( $page = 1, $args = null );
  • the_content_parts( $args = null );
  • get_the_content_parts( $args = null );
  • has_content_parts( $args = null );
  • count_content_parts( $args = null );

Example 1

To correctly show the first content part instead of the main the_content() tag.

<?php
if ( function_exists( 'the_content_part' ) ) {
	the_content_part( 1 );
} else {
	the_content();
}
?>

Example 2

Display the second content part. Checking that the function exists first will ensure compatibility if you deactivate the plugin.

<?php if ( function_exists( 'the_content_part' ) ) the_content_part( 2 ); ?>

Example 3

Display the third content part surrounded by a div.

<?php if ( function_exists( 'the_content_part' ) ) the_content_part( 3, array( 'before' => '<div class="content-area-3">', 'after' => '</div>' ) ); ?>

Example 4

A complex example. If there are multiple content parts, show the first content part followed by the next 3 content parts in a repeating set of styled divs. If you want to include all remaining content parts in the list, omit the ‘limit’ parameter.

<?php
if ( function_exists( 'the_content_part' ) && has_content_parts() ) {
	the_content_part( 1, '<div class="header">', '</div>' );
	the_content_parts( array(
		'before' => '<div class="item">',
		'after' => '</div>',
		'start' => 2,
		'limit' => 3
	) );
} else {
	the_content();
}
?>

Donate

Top Downloaded Mp3s
best dentist in los angeles
best web host
web hosting
vps hosting

61 Responses to “Content Parts”

  1. Valentin Says:

    Hi !
    Thanks for this plugin !

    But it does not work properly!
    In the loop, it only displays the contents of the first section and applied to others. This bug is a simple bug or it’s my loop ?

    Thanks ! :)

  2. Ben Says:

    So your seeing the first content part, but what do you mean “applied to others”?

    Have you added code into your theme to show the second part at all?

    < ?php if ( function_exists( 'the_content_part' ) ) the_content_part( 2 ); ?>
  3. jack Says:

    Brilliant plugin. Should become part of WP core imho. Makes all the other plugins for extra content blocks obsolete. Haven’t tested it yet though, but will soon.

  4. Valentin Says:

    @ben I mean,
    if I’ve 6 posts (in the loop) the 6 posts will display the contents of the first post (the first part)

  5. Ben Says:

    Do you have a link to an example I could see?

  6. Valentin Says:

    I have a preview (picture) -> http://gkr.fr/498R

  7. Ben Says:

    Valentin, is that an archive or category page? I’ve only tested it fully on single posts and pages at the moment.

    …or have you created a custom loop – if so how did you create your custom loop?

  8. John Saddington Says:

    that is pretty sweet. going to check it out.

  9. Simon Says:

    Hi

    This is a great idea for a plugin and I really like the way it’s done, but I’ve come across one problem: I’m putting a h1 or h2 header as the first line of each content part, but they are getting stripped out when the content parts are displayed.

    It seems to be because the opening h1 or h2 tag ends up being before the divider somehow.

    Not sure if this is an easy issue to sort out, as it’s caused by the TinyMCE editor more than your plugin I think?

  10. Ben Says:

    Simon,

    The Content part divider really needs to be on it’s own line in the editor. If it appears to be be included within a header tag, simply put an extra return in between the divider and the heading – that should sort it.

    - Ben

  11. Technology Global » WordPress Plugin Releases for 1/23 Says:

    [...] Content Parts allows you to split your editable content into multiple parts and display each part using template tags within your theme, allowing you to create complex content layouts. [...]

  12. Banago Says:

    Great plugin – Well done!

    I’ve been adding such functionality to a couple of themes, but having a icon on the editor to press when you need to is really great.

    Thanks for sharing this great work of yours.

  13. Vivek Parmar Says:

    That’s a nice plugin, will look forward to review it on my blog. Thanks for sharing new information

  14. WordPress Plugin Releases for 1/23 « Weblog Tools Collection Says:

    [...] Content Parts allows you to split your editable content into multiple parts and display each part using template tags within your theme, allowing you to create complex content layouts. [...]

  15. Roy Huggins Says:

    Hi Ben,

    This plugin looks very promising. I’m going to give it a try!

    Are there any plans to allow named parts? Seems like it would add robustness.

  16. Ben Says:

    Roy, no plans as yet. My next priority is to get it to work with paging functionality. Named parts would add an additional complexity to how you would manage this via the editor – if you have any thought please post them here…

  17. sebastian Says:

    hey ben,

    nice plugin! i’ve tried it on an archive page (which is where i could use it) but makes some problem. it takes the content part from the last post and puts it on all posts in the archive. any clue how to fix this?

    sebastian

  18. Ben Says:

    Sebastian,

    Where are you using on your archive page? and what do you expect it to display?

    - Ben

  19. sebastian Says:

    i mainly post movies with a discription on the side. when i list the posts in a category i would like to show a part of the post with a small preview image for each post. maybe i could include that in the post as a part…

  20. Ben Says:

    Do you have a link so I can see what you’re trying to do?
    You might be better of using the_post_thumbnail()

  21. sebastian Says:

    thanks! i will try that.i am working on localhost right now but you can see the original page i am updating here: http://www.pictoys.com.

  22. Dwaynne Says:

    This plugin is a life-saver! Simply brilliant! Saved my skin and easy for my client to use.

  23. Spice Up Your WordPress Theme Layout with Content Parts | Church Mag Says:

    [...] Download it here! [...]

  24. Pankaj | AndroidExpert Says:

    i was thinking for a split Post function in wordpress to split my big post into pieces and to update them, Your Code has saved lots of work of mine. I can quickly edit it and make the modification required for my work. Thanks for the awesome Job

  25. marc Says:

    hi,
    i created my own loop and then the plugin doesn’t work.
    my loop looks like this:

    $recentPosts = new WP_Query( );
    $recentPosts->query('post_type=page&orderby=menu_order&order=ASC');

    while ($recentPosts->have_posts()) : $recentPosts->the_post();

    the_content();
    works but not the
    the_content_part( 1 );
    can u help me please?

    thank you
    marc

  26. Anurag @ AndroidGyan Says:

    like to use the tag instead of the ‘more’ tag because as th3dark mentioned above the ‘more’ tag is usually used to show only a part of the content of a post or page.

    If you install the TinyMCE Advanced plugin you can add the “Split Page” icon to your editor (which looks very like the More Tag button) to easily insert these breaks. You’re unlikely to want to split a page into separate pages and have multiple content areas in the same template so this works quite well.

  27. Karth Says:

    Good Plugin

    How to extract the page content using ?
    the_content_part( $page = 1, $before = ”, $after = ” );

    Please any help appriciated.
    Kar

  28. Aleks Says:

    Hiya, nice plugin.. but having trouble with custom post types and the_content_part() function. Nothing comes out, though it loops through my own:

    foreach ( $content_parts as $page ) {

    statement.

    Any ideas on how to make this work with my custom post type?

    Thanks!

  29. Ben Says:

    @Aleks Can you confirm wether there is anything in the $content_parts variable when you loop though it?

    If not you need to make sure you are using it in the WordPress Loop. ie after the the_post() function in your template.

  30. Aleks Says:

    Here’s the kind of code i am using… granted my loop through the content parts as $page is maybe not quite right… but not even the first call to the_content_part(1, ”, ”) returns anything… the if has skips to the_content() …. so somehow its not seeing the function totally.. no php errors… thats why i think its custom post… functions dont error but return nothing.

    <?php
    $pagenumber = 0;
    $globalpagenumber = 0;
     
    query_posts( 'post_type=book&child_of=' . $id . '&order=ASC' );
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    	$globalpagenumber++;
    	$pagenumber=1;
    	?>
    	<section class="title- page-  globalPage-" style="z-index: 499; ">
    		<a href="">:</a>
    			2,
    			'post_type' => 'book'
    		) );
    } else {
    	the_content();
    }
     
    ?>
     
    <section class="title- page- globalPage-" style="z-index: 499; ">
     
    	<a href="">
    	 :</a>
  31. Aleks Says:

    hmm.. .seems like some stuff .. all te important stuff about content parts was stripped somehow?

  32. Ben Says:

    @Aleks Email me you code via my contact page

  33. Stephan Says:

    What a nice Plugin! But is it possible to set a custom Name to the dividers

    eg.

    divider1 = “Main Content”
    divider2 = “Header Section”
    divider3 = “Section in Sidebar 1″
    divider4 = “Section in Sidebar 2″
    divider5 = “Footer Section”

    i need this be because some Posts use only the Header Section, some use only Sidebar 1 & Sidebar 2, some use Footer Section & Sidebar2 ….

    it will be great to see this in the next future

    Thx
    Stephan

  34. Ben Says:

    That’s not currently possible but is definitely a feature I would like to look at adding in future.

  35. David McCormick Says:

    Hi – this looks ace; thanks very much.

    Is there a way to check how many parts there are? I’m looking to give each div a different class (probably something like, ‘item-1′, ‘item-2′ etc.) – and would need the number I think, somehow.

    I imagine this is probably related to Stephan’s question above, but I remain hopeful!

    Cheers,
    D

  36. David McCormick Says:

    Hey! I found count_content_parts()

    You should document that. This is excellent.

  37. Nestor Says:

    Excellent plugin,
    but how i can get a part outside the Loop?
    get_the_content_part(id_page,1) seems not to work

  38. Ben Says:

    The correct format is:

    get_the_content_part( 1, array( 'post_id' => $my_page_id ) );
  39. Nestor Says:

    Hi, thanks for the reply,
    I’ve tried the code above but it always return the contents of the current post not the content of $my_page_id.
    I’m trying to add a content part from another page into a new page.

  40. Nestor Says:

    Hi,
    I’ve used only the split_content_parts to get the parts of my desired post,
    it works well.

  41. sappho Says:

    Can exclude the split part from the main content?

  42. Ben Says:

    @sappho Not possible at present but I have added it as an enhancement to the issues list: https://github.com/benhuson/content-parts/issues

  43. Th90 Says:

    Hi.
    Your ‘content parts’ is a nice plugin.
    but it does not work inside the loop.
    Or i mistake.
    when i use this code inside the loop ( loop-search.php in this example ) :

    if ( function_exists( ‘the_content_part’ ) ) {
    the_content_part( 2 );
    } else {
    the_content();
    }

    and it outputs just the content of first result for all posts in the result !!
    is there any way to solve this problem?
    Thanks.

  44. Ben Huson Says:

    Please try downloading version 1.4 which I am just testing:
    https://github.com/benhuson/content-parts/tags

  45. Th90 Says:

    Hi again mr Ben Huson.
    Yes the 1.4 solved problem :D
    very nice.
    And it seems there is another problem or i am mistaking.
    the problem is that i’ve two themes on my wordpress site.
    on the first theme that i have used the code to load custom part of the content, it works correctly,
    but on the second template it loads just the first (1) part of content.
    is this problem is true or it’s a mistake from me.
    and the last question i have is :
    can i use this nice plugin to return the custom part into a variable? does get_the_content_part function work like the wordpress default tag get_the_content?
    Thank you very much.

  46. Ben Huson Says:

    Th90,
    The get_the_content_part() and get_the_content_parts() both return the content as variables.

  47. Th90 Says:

    Thanks for your help mr Ben.

  48. Keshav naidu Says:

    Hello Ben,

    Everything is working fine..
    but the problem is in Search:
    wen search the page showing results with “content 1st part” and ” –>” ..

    it should only show the title link.
    Please Help me..
    Thank you very much !

  49. Ben Huson Says:

    Is there a link so I can see your search results?

  50. ElectricPrism Says:

    I was hoping this plugin would fit my needs. Unfortunately it’s not fool proof enough to divide the content into separate wordpress textarea boxes.

    I’d pay fair money to get the functionality that http://WolfCMS.org has in parts in WordPress.

  51. Ben Huson Says:

    Sorry this plugin doesn’t fit your needs.
    Many other other people have found it useful – and it is provided for free.

  52. arkitect Says:

    Hi Ben,

    I’m using “Sliding Door” (in the WordPress by Wayne Connor) as my current theme. Each sliding door assigned to one of my seven categories.

    I also like to have seven parts ( from top to down, accordingly to above 7 sliding doors/categories) in main content of my Home page and each part will display the links of 5 latest posts in the specific category).

    Can I use your plug-in to serve this purpose? Or your plug-in is just adding dividers between displayed posts?

    Thank you in advance.

  53. Ben Huson Says:

    @arkitect This plugin does more than adding just divider lines. It allows you to add template tags into your theme files to display the different sections of editable content in different places in your template.

    If you are displaying your latest links by entering them into the editable content area either manually or via a shortcode, then you could use this plugin to split the content area into section to display them in a certain way in your templates.

    If you are displaying the latest links using code in your theme templates this plugin will not be of any help.

  54. Radek Says:

    Hello Ben

    It’s a REALLY nice plugin you made. I’m currently testing it and it works just great except for one thing. I’ve turned an HTML template into Wordpress theme and when I use content parts somehow an entire row is added below each content-part block, which messes up my layout because everything is being pushed down.

    As I was using the ‘surrounded by a div’ code from example 3 of your instruction above I thought the reason for that extra line was precisely that PHP-generated div container. So I switched to the code from example 2 (no div container there) and … nothing has changed. I mean, the extra row is still there.

    I noticed that when I edit Wordpress template and type the desired text the extra row disappears. But when I put back the content-part code the extra row comes back again.

    Two examples from my index.php file, both display the very same text, that is ‘Welcome’

    Welcome – no extra row displayed in a browser

    – extra row appears

    Any suggestions? I hope it’s just me doing something wrong, ’cause the plugin is just way too promising.

  55. Radek Says:

    Oops, I see my two examples got stripped of tags so you won’t understand what I meant. Let me try again (h1 below is of course html header tag)

    h1 Welcome /h1 – no extra row displayed in a browser

    h1 code_from_example_2_above /h1 – extra row appears

  56. Ben Huson Says:

    @Radek By default it applies the WordPress the_content filter on the output which means it is probably wrapping P tags around the content before yu put your H1 around it. Can you check?

  57. Radek Says:

    You’re right Ben, this is exactly what happens. Here’s how I got rid of the P tags:

    1. I put the content into a variable like that:
    variable = get_the_content_ part

    2. Used a PHP function to remove the P tags:
    echo strip_tags (variable)

    It works, though there might be a more gracious way of doing it.

    Anyway, thanks for help Ben.

  58. hopscotch Says:

    I’m always using for spliting the content, now I found this but it seem there is debating about this plugin.. I’l give it try .

  59. JayDee Says:

    Hi Ben,

    Thanks for the plugin work. I have found an issue on line 68 of content-parts.php. You are checking strpos() against integer, instead of against boolean, therefore throwing false negative if strpos is == 0.

    Currently reads:

    if ( strpos( $content, ‘‘ ) ) {

    Should read:

    if ( strpos( $content, ‘‘ ) !== false ) {

    Cheers,
    JD

  60. jvzoo Says:

    thanks for info :)

  61. Ben Huson Says:

    @JayDee Thanks. Will fix that.

Leave a Reply