0

我正在编辑 wordpress 帖子的代码页。

现在这里是完整的页面代码:

<?php

    add_action( 'init', 'create_recipes' );
    function create_recipes() {
        //$portfolio_translation = get_option(THEME_NAME_S.'_cp_portfolio_slug','portfolio');

        $labels = array(
            'name' => _x('Recipes', 'Recipe General Name', 'crunchpress'),
            'singular_name' => _x('Recipe Item', 'Recipe Singular Name', 'crunchpress'),
            'add_new' => _x('Add New', 'Add New Event Name', 'crunchpress'),
            'add_new_item' => __('Add New Recipe', 'crunchpress'),
            'edit_item' => __('Edit Recipe', 'crunchpress'),
            'new_item' => __('New Recipe', 'crunchpress'),
            'view_item' => __('View Recipe', 'crunchpress'),
            'search_items' => __('Search Recipe', 'crunchpress'),
            'not_found' =>  __('Nothing found', 'crunchpress'),
            'not_found_in_trash' => __('Nothing found in Trash', 'crunchpress'),
            'parent_item_colon' => ''
        );

        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            'menu_icon' => CP_PATH_URL . '/framework/images/recipe-icon.png',
            'rewrite' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'menu_position' => 5,
            'supports' => array('title','editor','author','thumbnail','excerpt','comments'),
            'rewrite' => array('slug' => 'recipes', 'with_front' => false)
          ); 

        register_post_type( 'recipes' , $args);

        register_taxonomy(
            "recipe-category", array("recipes"), array(
                "hierarchical" => true,
                "label" => "Recipe Categories", 
                "singular_label" => "Recipe Categories", 
                "rewrite" => true));
        register_taxonomy_for_object_type('recipe-category', 'recipes');

        register_taxonomy(
            "recipe-tag", array("recipes"), array(
                "hierarchical" => false, 
                "label" => "Recipe Tag", 
                "singular_label" => "Recipe Tag", 
                "rewrite" => true));
        register_taxonomy_for_object_type('recipe-tag', 'recipes');

    }


    add_action('add_meta_boxes', 'add_recipes_option');
    function add_recipes_option(){  

        add_meta_box('recipe-option', __('Recipes Options','crunchpress'), 'add_recipe_option_element',
            'recipes', 'normal', 'high');

    }
    function add_recipe_option_element(){
        $recipe_price = '';
        $recipe_social = '';
        $sidebars = '';
        $right_sidebar_recipe = '';
        $left_sidebar_recipe = '';
        $recipe_detail_xml = '';
        $select_chef = '';
        $recipe_url = '';


    foreach($_REQUEST as $keys=>$values){
        $$keys = $values;
    }
    global $post;

    $recipe_detail_xml = get_post_meta($post->ID, 'recipe_detail_xml', true);
    $ingredients_settings = get_post_meta($post->ID, 'ingredients_settings', true);
    $nutrition_settings = get_post_meta($post->ID, 'nutrition_settings', true);

    if($recipe_detail_xml <> ''){

        $cp_recipe_xml = new DOMDocument ();
        $cp_recipe_xml->loadXML ( $recipe_detail_xml );
        $recipe_price = find_xml_value($cp_recipe_xml->documentElement,'recipe_price');
        $recipe_url = find_xml_value($cp_recipe_xml->documentElement,'recipe_url');
        $recipe_social = find_xml_value($cp_recipe_xml->documentElement,'recipe_social');
        $sidebars = find_xml_value($cp_recipe_xml->documentElement,'sidebars');
        $left_sidebar_recipe = find_xml_value($cp_recipe_xml->documentElement,'left_sidebar_recipe');
        $right_sidebar_recipe = find_xml_value($cp_recipe_xml->documentElement,'right_sidebar_recipe');
    }
    ?>
        <div class="event_options">
            <ul class="recipe_class top-bg">
                <li><h2>Recipe Options and Social Sharing</h2></li>
            </ul>
            <ul class="recipe_class">
                <li class="panel-title">
                    <label for="recipe_social" > <?php _e('SOCIAL NETWORKING', 'crunchpress'); ?> </label>
                </li>   
                <li class="panel-input">
                    <label for="recipe_social"><div class="checkbox-switch <?php

                    echo ($recipe_social=='enable' || ($recipe_social=='' && empty($default)))? 'checkbox-switch-on': 'checkbox-switch-off'; 

                ?>"></div></label>
                <input type="checkbox" name="recipe_social" class="checkbox-switch" value="disable" checked>
                <input type="checkbox" name="recipe_social" id="recipe_social" class="checkbox-switch" value="enable" <?php 

                    echo ($recipe_social=='enable' || ($recipe_social=='' && empty($default)))? 'checked': ''; 

                ?>>
                </li>
                <li class="description"><p>Turn On/Off Social Sharing on Event Detail.</p></li>
            </ul>
            <div class="clear"></div>
            <ul class="recipe_class">
                <li class="panel-title">
                    <label for="recipe_price" > <?php _e('RECIPE PRICE', 'crunchpress'); ?> </label>
                </li>               
                <li class="panel-input">
                    <input type="text" name="recipe_price" id="recipe_price" value="<?php if($recipe_price <> ''){echo $recipe_price;};?>" />
                </li>
                <li class="description"><p>Please enter your recipe price.</p></li>
            </ul>   
            <div class="clear"></div>
            <!--david-->
            <ul class="recipe_class">
                <li class="panel-title">
                    <label for="recipe_url" > <?php _e('RECIPE URL', 'crunchpress'); ?> </label>
                </li>               
                <li class="panel-input">
                    <input type="text" name="recipe_url" id="recipe_url" value="<?php if($recipe_url <> ''){echo $recipe_url;};?>" />
                </li>
                <li class="description"><p>Please enter your url</p></li>
            </ul>   
            <div class="clear"></div>
            <!--david end-->
            <?php echo show_sidebar($sidebars,'right_sidebar_recipe','left_sidebar_recipe',$right_sidebar_recipe,$left_sidebar_recipe);?>
            <ul class="recipe_class">
                <li class="panel-title">
                    <label><?php _e('Add Ingredients', 'crunchpress'); ?></label>
                </li>
                <li class="panel-input">
                    <input type="text" id="add-more-ingre" value="type title here" rel="type title here">
                    <div id="add-more-ingre" class="add-more-ingre"></div>
                </li>
                <li class="description"><p>Add Ingredients for this recipe.</p></li>
                <div class="clear"></div>
                <ul class="nut_table">
                    <li>
                        <div>SrNo</div>
                        <div>Name</div>
                        <div class="panel-delete-cc">&nbsp;</div>
                    </li>
                </ul>
                <ul id="selected-ingre" class="selected-ingre nut_table_inner">
                    <li class="default-ingre-item" id="ingre-item">
                        <div class="ingre-item-counter"></div>
                        <div class="ingre-item-text"></div>
                        <div class="panel-delete-ingre"></div>
                        <input type="hidden" id="ingredients">
                    </li>
                <?php
                //Sidebar addition
                if($ingredients_settings <> ''){
                    $ingre_xml = new DOMDocument();
                    $ingre_xml->loadXML($ingredients_settings);
                    $counter = 0;
                    foreach( $ingre_xml->documentElement->childNodes as $ingre_name ){
                    $counter++;
                    ?>
                    <li class="ingre-item" id="ingre-item">
                        <div class="ingre-item-counter"><?php echo $counter;?></div>
                        <div class="ingre-item-text"><?php echo $ingre_name->nodeValue; ?></div>
                        <div class="panel-delete-ingre"></div>
                        <input type="hidden" name="ingredients[]" id="ingredients" value="<?php echo $ingre_name->nodeValue; ?>">
                    </li>
                <?php }
                }
                ?>
                </ul>
            </ul>   
            <div class="clear"></div>
            <ul class="recipe_class">
                <li class="panel-title">
                    <label> <?php _e('Add Nutrition', 'crunchpress'); ?> </label>
                </li>
                <li class="panel-input">
                    <input type="text" id="add-more-nutrition" value="type title here" rel="type title here">
                    <div id="add-more-nutrition" class="add-more-nutrition"></div>
                </li>
                <li class="description"><p>Add Nutrition for this recipe.</p></li>
                <div class="clear"></div>
                <ul class="nut_table">
                    <li>
                        <div>SrNo</div>
                        <div>Name</div>
                        <div class="panel-delete-cc">&nbsp;</div>
                    </li>
                </ul>
                <br class="clear">
                <ul id="selected-nutrition" class="selected-nutrition nut_table_inner">
                    <li class="default-nutrition-item" id="nutrition-item">
                        <div class="nut-item-counter"></div>
                        <div class="nutrition-item-text"></div>
                        <div class="panel-delete-nutrition"></div>
                        <input type="hidden" id="nutrition">
                    </li>
                <?php
                //Sidebar addition
                if($nutrition_settings <> ''){
                    $ingre_xml = new DOMDocument();
                    $ingre_xml->loadXML($nutrition_settings);
                    $counter = 0;
                    foreach( $ingre_xml->documentElement->childNodes as $ingre_name ){
                    $counter++;
                    ?>
                    <li class="nutrition-item" id="nutrition-item">
                        <div class="nut-item-counter"><?php echo $counter;?></div>
                        <div class="nutrition-item-text"><?php echo $ingre_name->nodeValue; ?></div>
                        <div class="panel-delete-nutrition"></div>
                        <input type="hidden" name="nutrition[]" id="nutrition" value="<?php echo $ingre_name->nodeValue; ?>">
                    </li>
                <?php }
                }
                ?>
                </ul>
            </ul>           
            <div class="clear"></div>
            <ul class="recipe_class">
                <li class="panel-title">
                    <label for="select_chef"><?php _e('SELECT CHEF', 'crunchpress'); ?></label>
                </li>               
                <li class="panel-input">    
                    <div class="combobox">
                        <select name="select_chef" id="select_chef">
                        <option>-- Select Chef --</option>
                        <?php

                        foreach(get_title_list_array('teams') as $our_team){?>
                            <option <?php if($select_chef == $our_team->post_name){echo 'selected';}?> value="<?php echo $our_team->post_name;?>"><?php echo $our_team->post_title?></option>
                        <?php }?>
                        </select>
                    </div>
                </li>
                <li class="description"><p>Please select Chef of this recipe.</p></li>
            </ul>   
            <div class="clear"></div>
            <input type="hidden" name="nutrition_type" value="nutrition">           
            <div class="clear"></div>
        </div>  
        <div class="clear"></div>
    <?php }
    add_action('save_post','save_recipe_option_meta');
    function save_recipe_option_meta($post_id){

        $recipe_social = '';
        $sidebars = '';
        $right_sidebar_recpie = '';
        $left_sidebar_recpie = '';

        foreach($_REQUEST as $keys=>$values){
            $$keys = $values;
        }

        if(defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE) return;

        if(isset($nutrition_type) AND $nutrition_type == 'nutrition'){

        $new_data = '<recipe_detail>';
        $new_data = $new_data . create_xml_tag('recipe_price',$recipe_price);
        $new_data = $new_data . create_xml_tag('recipe_url',$recipe_url);
        $new_data = $new_data . create_xml_tag('recipe_social',$recipe_social);
        $new_data = $new_data . create_xml_tag('sidebars',$sidebars);
        $new_data = $new_data . create_xml_tag('right_sidebar_recipe',$right_sidebar_recipe);
        $new_data = $new_data . create_xml_tag('left_sidebar_recipe',$left_sidebar_recipe);
        $new_data = $new_data . '</recipe_detail>';

        //Saving Sidebar and Social Sharing Settings as XML
        $old_data = get_post_meta($post_id, 'recipe_detail_xml',true);
        save_meta_data($post_id, $new_data, $old_data, 'recipe_detail_xml');

        $recipe_setting_xml = '<recipe_ingredients>';
        if(isset($_POST['ingredients'])){$ingredients = $_POST['ingredients'];
            foreach($ingredients as $keys=>$values){
                $recipe_setting_xml = $recipe_setting_xml . create_xml_tag('ingredients',$values);
            }
        }else{$ingredients = '';}
        $recipe_setting_xml = $recipe_setting_xml . '</recipe_ingredients>';

        //Saving Sidebar and Social Sharing Settings as XML
        $old_data_ingre = get_post_meta($post_id, 'ingredients_settings',true);
        save_meta_data($post_id, $recipe_setting_xml, $old_data_ingre, 'ingredients_settings');

        $nutrition_setting_xml = '<recipe_nutrition>';
        if(isset($_POST['nutrition'])){$nutrition = $_POST['nutrition'];
            foreach($nutrition as $keys=>$values){
                $nutrition_setting_xml = $nutrition_setting_xml . create_xml_tag('nutrition',$values);
            }
        }else{$nutrition = '';}
        $nutrition_setting_xml = $nutrition_setting_xml . '</recipe_nutrition>';

        //Saving Sidebar and Social Sharing Settings as XML
        $old_data_nut = get_post_meta($post_id, 'nutrition_settings',true);
        save_meta_data($post_id, $nutrition_setting_xml, $old_data_nut, 'nutrition_settings');

        }
    }



    //FRONT END RECIPE LAYOUT
    $recipe_div_size_num_class = array(
        "Full-Image" => array("index"=>"1", "class"=>"sixteen ", "size"=>array(300,110), "size2"=>array(300,110), "size3"=>array(300,110)),
        "Small-Thumbnail" => array("index"=>"2", "class"=>"sixteen", "size"=>array(445,175), "size2"=>array(445,175), "size3"=>array(445,175)));


    // Print Recipe item
    function print_recipe_item($item_xml){
    wp_reset_query();
        global $paged,$sidebar,$recipe_div_size_num_class,$post,$wp_query,$counter;?>
        <!--<script src="<?php echo CP_PATH_URL;?>/frontend/js/jquery-filterable.js" type="text/javascript"></script>-->
    <?php
        if(empty($paged)){
            $paged = (get_query_var('page')) ? get_query_var('page') : 1; 
        }
        //echo '<pre>';print_r($item_xml);die;
        //print_r($event_div_size_num_class);
        //$item_type = find_xml_value($item_xml, 'recipe-thumbnail-type');
        $item_type = 'Full-Image';
        // get the item class and size from array
        $item_class = $recipe_div_size_num_class[$item_type]['class'];
        $item_index = $recipe_div_size_num_class[$item_type]['index'];
        $full_content = find_xml_value($item_xml, 'show-full-news-post');
        if( $sidebar == "no-sidebar" ){
            $item_size = $recipe_div_size_num_class[$item_type]['size'];
        }else if ( $sidebar == "left-sidebar" || $sidebar == "right-sidebar" ){
            $item_size = $recipe_div_size_num_class[$item_type]['size2'];
        }else{
            $item_size = $recipe_div_size_num_class[$item_type]['size3'];
        }


        // get the blog meta value      
        $header = find_xml_value($item_xml, 'header');
        $num_fetch = find_xml_value($item_xml, 'num-fetch');
        $num_excerpt = find_xml_value($item_xml, 'num-excerpt');



        $category = find_xml_value($item_xml, 'category');
        $show_filterable = find_xml_value($item_xml, 'show-filterable');
        $category_name = '';
        $category = ( $category == 'All' )? '': $category;
        if( !empty($category) ){
            $category_term = get_term_by( 'name', $category , 'recipe-category');
            $category = $category_term->term_id;
            $category_name = $category_term->name;
        }

    ?>
    <h2  class="heading"><?php echo $header;?></h2>
    <?php 
    //Filterable Recipe Script start
    if($show_filterable == 'Yes'){?>
    <script>
        jQuery(window).load(function() {
            var filter_container = jQuery('#portfolio-item-holder<?php echo $counter?>');

            filter_container.children().css('position','absolute'); 
            filter_container.masonry({
                singleMode: true,
                itemSelector: '.portfolio-item:not(.hide)',
                animate: true,
                animationOptions:{ duration: 800, queue: false }
            }); 
            jQuery(window).resize(function(){
                var temp_width =  filter_container.children().filter(':first').width() + 20;
                filter_container.masonry({
                    columnWidth: temp_width,
                    singleMode: true,
                    itemSelector: '.portfolio-item:not(.hide)',
                    animate: true,
                    animationOptions:{ duration: 800, queue: false }
                });     
            }); 
            jQuery('ul#portfolio-item-filter<?php echo $counter?> a').click(function(e){    

                jQuery(this).addClass("active");
                jQuery(this).parents("li").siblings().children("a").removeClass("active");
                e.preventDefault();

                var select_filter = jQuery(this).attr('data-value');

                if( select_filter == "All" || jQuery(this).parent().index() == 0 ){     
                    filter_container.children().each(function(){
                        if( jQuery(this).hasClass('hide') ){
                            jQuery(this).removeClass('hide');
                            jQuery(this).fadeIn();
                        }
                    });
                }else{
                    filter_container.children().not('.' + select_filter).each(function(){
                        if( !jQuery(this).hasClass('hide') ){
                            jQuery(this).addClass('hide');
                            jQuery(this).fadeOut();
                        }
                    });
                    filter_container.children('.' + select_filter).each(function(){
                        if( jQuery(this).hasClass('hide') ){
                            jQuery(this).removeClass('hide');
                            jQuery(this).fadeIn();
                        }
                    });
                }

                filter_container.masonry(); 

            });
        });
        </script>   
    <ul id="portfolio-item-filter<?php echo $counter?>" class="category-list">
        <li><a data-value="all" class="gdl-button active" href="#">All</a></li>
        <?php

        $categories = get_categories( array('child_of' => $category, 'taxonomy' => 'recipe-category', 'hide_empty' => 0) );
        //$categories = get_the_terms( $post->ID, 'recipe-category' );                               
            if($categories <> ""){
                foreach($categories as $values){?>
                <li><a data-value="<?php echo $values->term_id;?>" class="gdl-button" href="#"><?php echo $values->name;?></a></li>                                
            <?php
                }
            }?>                            
        <div class="clear"></div>
    </ul>
    <?php }else{?>
        <h2 class="heading"><?php echo $category_name; ?></h2>
    <?php }?>                 
    <ul class="lightbox gallery_filterable" id="portfolio-item-holder<?php echo $counter?>">
    <?php
    $category = find_xml_value($item_xml, 'category');
    $category = ( $category == 'All' )? '': $category;
        if( !empty($category) ){
            $category_term = get_term_by( 'name', $category , 'recipe-category');
            $category = $category_term->slug;
        }
        if($show_filterable == 'Yes'){
        query_posts(array(
            'posts_per_page'            => -1,
            'post_type'                 => 'recipes',
            'recipe-category'           => $category,
            'post_status'               => 'publish',
            'order'                     => 'ASC',
            ));
        }else{
        query_posts(array(
            'posts_per_page'            => $num_fetch,
            'paged'                     => $paged,
            'post_type'                 => 'recipes',
            'recipe-category'           => $category,
            'post_status'               => 'publish',
            'order'                     => 'ASC',
            ));
        }
        while( have_posts() ){
        global $post;
        the_post(); ?>
                <li class="all portfolio-item item alpha
                    <?php
                    $categories = get_the_terms( $post->ID, 'recipe-category' );
                        if($categories <> ''){
                            foreach ( $categories as $category ) {
                                echo $category->term_id." ";
                            }
                        }
                    ?>">
                    <h3 class="heading">
                        <a href="<?php echo get_permalink();?>">
                            <?php 
                            echo substr($post->post_title, 0, 20);
                            if ( strlen($post->post_title) > 20 ) echo "...";
                            ?>
                        </a>
                    </h3>
                    <a href="<?php echo get_permalink();?>" class="caption">                                         
                        <?php echo get_the_post_thumbnail($post->ID, $item_size);?> 
                        <span class="hover-effect big zoom"></span>
                    </a>
                    <!--david-->
                    <article class="menu-det">
                        <p><?php echo strip_tags(mb_substr(get_the_content(),0,$num_excerpt));?> <a class="c-link" href="<?php echo $recipe_url;?>"><?php _e('Read More...', 'crunchpress'); ?></a></p>
                    </article>                                                          
                </li>
    <?php }//End While?>
    </ul> 
        <div class="clear"></div>
        <?php
        if( find_xml_value($item_xml, "pagination") == "Yes" AND $show_filterable == 'No'){ 
            pagination();
        }   


     }  

?>

现在,在上面这个页面的底部,您将看到一个包含以下内容的 readmore 链接:

<article class="menu-det">
    <p><?php echo strip_tags(mb_substr(get_the_content(),0,$num_excerpt));?> <a class="c-link" href="<?php echo $recipe_url;?>"><?php _e('Read M...', 'crunchpress'); ?></a></p>
</article>  

现在给我问题的部分是这个:

<?php echo $recipe_url;?>

所以我基本上只注册了一个新变量:$recipe_url; ,我替换了原来的链接href值:

href="<?php echo get_permalink()?>"

使用我的新变量:

href="<?php echo $recipe_url;?>"

现在网页上的 url 是空的,即使设置了一个值。我什至使用了主题中包含的一些原始变量:

href="<?php echo $recipe_price;?>"

但它也不会填充任何 url 或 href 值..

为什么是这样?我叫错了吗?

谢谢

4

1 回答 1

0

I don't have enough rep to add a comment to the question, but you don't appear to have added a closing brace to the add_recipe_option_element() method either.

于 2013-09-15T17:22:30.543 回答