检索unctions.php中的NEXT_POST_LINK()和PREVICE_POST_LINK()

时间:2012-09-26 作者:Gab

我试图在函数中创建一个函数。包含下一个\\u post\\u link()和上一个\\u post\\u link()的php,但未成功。它返回空。我的猜测是这些没有使用post ID。。。那么,为了在下面的代码中将它们的值存储在$next\\u link和$previous\\u link中,最好的方法是什么呢?

<?php
function get_all_images($post_id=0, $size=\'poster\', $attributes=\'\') {
    $post_id = $_POST[\'post_id\'];
    if ($post_id<1) $postid = get_the_ID();
    if ($images = get_children(array(
        \'post_parent\' => $post_id,
        \'post_type\' => \'attachment\',
        \'numberposts\' => -1,
        \'orderby\' => \'menu_order\',
        \'post_mime_type\' => \'image\',)))
        $title = get_the_title($post_id);
        $next_link = next_post_link($post_id);
        $previous_link = previous_post_link($post_id);
        $response = \'<div class="post-control left">\'.$next_link.\'</div><div class="post-control right">\'.$previous_link.\'</div><div class="post-titles titles">\'.$title.\'<span class="ajust-icon pull-right"><a href="/blog" class="backtoblog"><i class="icon-remove icon-white"></i></a></span></div>\';
        foreach($images as $image) {
            $attachment=wp_get_attachment_image_src($image->ID, $size);
            $tranparent=get_template_directory_uri();
            $response .= \'<img src="\'.$tranparent.\'/images/transparent.gif" data-original="\'.$attachment[0].\'" alt="" class="imarge" />\';
        }
    $get_post = get_post($post_id);
    $get_content = $get_post -> post_content;
    $content = apply_filters(\'the_content\', $get_content);
    $content = str_replace(\']]>\', \']]&gt;\', $content);
    die(json_encode($response.$content));
}?>

1 个回复
最合适的回答,由SO网友:Gab 整理而成
<?php
function get_all_images($post_id=0, $size=\'poster\', $attributes=\'\') {
    global $post;
    setup_postdata($post);
    $post_id = $_POST[\'post_id\'];
    if ($post_id<1) $postid = get_the_ID();
    $post = get_post($post_id);
    $get_content = $post -> post_content;
    $content = apply_filters(\'the_content\', $get_content);
    $content = str_replace(\']]>\', \']]&gt;\', $content);
    $title = get_the_title($post);
    $previous_post = get_previous_post();
    $next_post = get_next_post();
    $previous_link_url = get_permalink(get_previous_post(false,\'\',true));
    $next_link_url = get_permalink(get_next_post(false,\'\',false));
    if (!empty( $previous_post )) $previous_link = \'<div class="post-control right"><a href="\'.$previous_link_url.\'" rel="prev">&rsaquo;</a></div>\';
    if (!empty( $next_post )) $next_link = \'<div class="post-control left"><a href="\'.$next_link_url.\'" rel="next">&lsaquo;</a></div>\';
    if ($images = get_children(array(
        \'post_parent\' => $post_id,
        \'post_type\' => \'attachment\',
        \'numberposts\' => -1,
        \'orderby\' => \'menu_order\',
        \'post_mime_type\' => \'image\',))) 
        $response = $previous_link.$next_link.\'<div class="post-titles titles">\'.$title.\'<span class="ajust-icon pull-right"><a href="/blog" class="backtoblog"><i class="icon-remove icon-white"></i></a></span></div>\';
        foreach($images as $image) {
            $attachment=wp_get_attachment_image_src($image->ID, $size);
            $tranparent=get_template_directory_uri();
            $response .= \'<img src="\'.$tranparent.\'/images/transparent.gif" data-original="\'.$attachment[0].\'" alt="" class="imarge" />\';
        }
    die(json_encode($response.$content));
}?>
结束

相关推荐

Functions.php:从博客中排除类别

所以很明显,如何从模板中排除某些类别,但我不想修改4个模板,使它们忽略某个类别。有没有一种方法可以将某个类别从阅读设置的“博客”集中排除?我正在将博客分配到名为“博客”的页面。。。但显然,档案和搜索也需要对这一超出类别的内容视而不见。我宁愿在里面做functions.php