Hey guys, I have problems encoding shortcodes. I want the code to display a div with a submission counter function, and then a link with the contents of the code files as a URL.
View_count (); the function works fine when called inside the theme files, and I really managed to show it, but then it appears before the_content (); (gray column) when I wanted it within the content under the element.
(1) Here is what I have:
function video_block( $atts, $content = null ) {
return '<div class="video-block"><span class="ViewCount"><?php the_views(); ?></span> <a class="dl-source" href="' . $content . '">Link</a></div>';
}
(2) Here is the code that appears at the top of the page:
function video_block( $atts, $content = null ) { ?>
<div class="video-block"><span class="ViewCount"><?php the_views(); ?></span> <a class="dl-source" href="<?php echo $content; ?>">Link</a></div>
<?php }
(3) This code displays the above views and the link in the right place:
function video_block( $atts, $content = null ) {
$views = the_views();
return '<div class="video-block"><span class="ViewCount"><?php $views; ?></span> <a class="dl-source" href="<?php echo $content; ?>">Link</a></div>';
}
- Wordpress, ( ) , , , html $content.
: http://nvrt.me/4Qf1 ( №2)
. , - .
EDIT:
the_views(); . , , , .
function the_views($display = true, $prefix = '', $postfix = '', $always = false) {
$post_views = intval(post_custom('views'));
$views_options = get_option('views_options');
if ($always || should_views_be_displayed($views_options)) {
$output = $prefix.str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $views_options['template']).$postfix;
if($display) {
echo apply_filters('the_views', $output);
} else {
return apply_filters('the_views', $output);
}
}
elseif (!$display) {
return '';
}
}