Created
February 11, 2014 17:12
-
-
Save RalfAlbert/8939355 to your computer and use it in GitHub Desktop.
WordPress: Zerlegt einen Text in zwei Spalten und verteilt die SApalten auf Seiten.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$content = | |
<<<CONTENT | |
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | |
CONTENT; | |
function columns_and_pages( $content = NULL ) { | |
if ( empty( $content ) ) | |
return $content; | |
$pages = array(); | |
$offset = 0; | |
$words_per_column = 5; | |
$words_per_page = $words_per_column * 2; | |
$parts = explode( ' ', $content ); | |
$word_count = count( $parts ); | |
while ( ! empty( $parts ) ) { | |
$pieces = array_slice( $parts, 0, $words_per_page ); | |
array_splice( $parts, 0, $words_per_page ); | |
$left = sprintf( | |
'<div class="left_column">%s</div>', | |
implode( ' ', array_slice( $pieces, 0, $words_per_column ) ) | |
); | |
$right = sprintf( | |
'<div class="right_column">%s</div>', | |
implode( ' ', array_slice( $pieces, $words_per_column, $words_per_column ) ) | |
); | |
$pages[] = $left . $right; | |
} | |
return implode( '<!--nextpage-->', $pages ); | |
} | |
$new_content = columns_and_pages( $content ); | |
?> | |
<html> | |
<head> | |
<title>Testseite</title> | |
<style type="text/css"> | |
.page { | |
width: 10em; | |
border: 1px solid black; | |
padding: 0.25em; | |
} | |
.left_column { | |
float: left; | |
border-right: 1px solid #aaa; | |
width: 3em; | |
} | |
.right_column { | |
float: left; | |
margin-left: 1em; | |
width: 3em; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Testausgabe</h1> | |
<div class="page"> | |
<?php print( $new_content ); ?> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment