$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>get posts - get_post Question|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

get posts - get_post Question

matteradmin10PV0评论

We have a custom post that displays a main post and several child posts. The main parent post displays a table with a summery of specs for the product. at the bottom of the table we have a link to a child page that displays the full specs page. This page uses a template: page-specs.php. This was once working but no longer working. The page links to the current parent page.

    function get_full_stats_page($post_id) {
        $args  = array('post_parent' => $post_id, 'post_type' => 'reviews', 'meta_key' => '_wp_page_template', 'meta_value' => 'page-specs.php', 'posts_per_page' => 1);
        $posts = get_posts( $args );

        if(isset($posts[0])) 
            return get_permalink($posts[0]->ID);
        return false;
    }


/*
 * Custom shortcode to display specs table
 * This sidebar is used to display specs table of current post and also finds a link for full specifications page.
 [reviews-specs-table]
 * Author - Preetam
 */


add_shortcode('reviews-specs-table', 'reviews_specs_table_handler');

function reviews_specs_table_handler() {
    $full_specs = get_full_stats_page($post->ID);
     //$full_specs = get_specs_link($post->ID);

$manufacturer = array_pop(get_the_terms($post->ID,'manufacturers'))->name;
$specs = array(
    'price' => 'Price',
    'technology' => 'Technology',
    'native_resolution' => 'Native Resolution',
    'brightness' => 'Brightness (Manufacturer Claim)',
    'contrast' => 'Contrast',
    'zoom_lens_ratio' => 'Zoom Lens Ratio',
    'lens_shift' => 'Lens Shift',
    'lamp_life' => 'Lamp Life',
    'weight' => 'Weight',
    'warranty' => 'Warranty'
);

$table = "";
$table .= '<table id="specs-preview" class="table table-responsive table-striped table-bordered specList" cellpadding="5" cellspacing="2">';
    $table .= '<thead>';
        $table .= '<tr>';
            $table .= '<th class="sec-header" colspan="2">' . $manufacturer . " " . get_field('model_number') . ' Specs</th>';
        $table .= '</tr>';
$table .= '</thead>';

$table .= '<tbody>';

foreach ( $specs as $spec => $title )
{
        $field = get_field( $spec );
        $table .=  '<tr>';
                $table .=  '<td class="title">' . $title . '</td>';
                $table .=  '<td>' . filter_pr_review( $spec, get_field($spec) ) . '</td>';
        $table .=  '</tr>';
}

$table .= '</tbody>';

$table .= '<tfoot>';
    $table .= '<tr>';
            if($full_specs){
                $table .= '<td colspan="2"><a href="' . get_permalink($full_specs->ID) . '">View Full Specifications Here &gt;&gt;</a></td>';
                $table .= '<td colspan="2"></td>';
            }else{
                $table .= '<td colspan="2">&nbsp;</td>';
            }
    $table .= '</tr>';
$table .= '</tfoot>';

$table .= '</table>';

return $table;
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far