Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter FAMC

    (@famc)

    Marios, the stripslashes did not solve it.

    All of us continued to have the textarea in the displayed “Settings” shown as one line. This was difficult to update.

    After lots of experimentation, I came up with something that works.

    The only change is to the “settings_page” function, in the admin.php file.

    Here is the patch:

    $optstr = "";
                        //newly defined
    
    		if ( isset($_POST['update']) ) {
    			// check user is authorised
    			if ( function_exists( 'current_user_can' ) && !current_user_can( 'manage_options' ) )
    				die( 'Sorry, not allowed...' );
    			check_admin_referer( 'pc_robotstxt_settings' );
    
    			$options['user_agents'] = trim( $_POST['user_agents'] );
    
                          //Changes below: treat lines of post data as an array
    			$options['user_agents'] = explode(PHP_EOL, $options['user_agents']);
    			$options['user_agents'] = array_filter($options['user_agents'], 'trim');
                                   // remove any extra \r characters left behind
    
    			foreach ($options['user_agents'] as $line) {
        				$optstr .= $line . "";
                                         //blank text at end of line prevents run-on text
    			}
    			$options['user_agents'] = $optstr;
                                    //reassign
    
    			isset( $_POST['remove_settings'] ) ? $options['remove_settings'] = true : $options['remove_settings'] = false;
    
    			update_option( 'pc_robotstxt', $options );
    
    			echo '<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>';
    
    		}
    		else {
    			$options['user_agents'] = explode(PHP_EOL, $options['user_agents']);
    			$options['user_agents'] = array_filter($options['user_agents'], 'trim');
                                // remove any extra \r characters left behind
    
    			foreach ($options['user_agents'] as $line) {
        				$optstr .= $line . "";
                                       //blank text at end of line prevents run-on text
    			}
    			$options['user_agents'] = $optstr;
                                 //reassign
    		}

    Essentially and oddly, the important change here is to separate the $options[‘user_agent’] lines into an array, and add nothing more than a double quoted empty text to the end of each line:

    $optstr .= $line . "";

    A double quoted newline does not work; nor does an escaped newline work; nor does nl2br function work. However anything a blank text added works. Don’t ask me why.

    I had to add the else-block, because whether the result of a Post or a pull of the current Robots file, the effect was the same—a single line of text displayed on the textarea. Thus Post results and pull results are treated equally.

    Perhaps it is only Macs that ever had this problem? I don’t know. But if so, it’s fixed with this patch, even with stripslashes left in.

    Thanks, Marios. I like your plugin very much. Now it’s perfect and convenient.
    –Fran Corpier

    Thread Starter FAMC

    (@famc)

    Thank you Marios! I’ll check it out, test and report back. Sure appreciate it.

    Got it – the dynamic side of it that is.
    (The above post was a static test, and let me to uncover just what get_post_custom_values("category-include") meant; as my theme example pages, and documentation made no other mention of ‘category- include’, other than in these templates.

    Summary: By adding the custom field, “category-include” into your category-specific
    page, and setting its value to the category slug; a selected template that
    uses the php code:
    $values = get_post_custom_values("category-include"); $cat=$values[0];
    $catinclude = 'portfolio_category='. $cat ;
    to build a query, will be able to dynamically pull just the categories
    specified for each specific page using the template.

    Detail:

    • First go to Pages.
    • Find the Page that will be your very specific category page.
    • In the Page Attributes, you will see the template that you’ve chosen
      for this page. For example, “Folio 3” (you can rename it after you have tested your category).
    • Click “Screen Options” at the top right of the Admin area for this page.
      Check “Custom Fields” in the screen options. This is the key to the whole shebang!

    The “category-include“, in the template stumped me, until I realized that it is a custom field name. None of my pages had this particular custom field name. The solution continues, below.

    • You should now have a custom field section in the base of your “Edit” screen for this page.
    • Your template providers may have a drop down list of preset custom fields. For example: “lightbox_url” and “thumb”. Do not select a preset unless you see “category-include” in the list. If so select it.
    • Otherwise, click the small link below the drop down menu that says,
      “Enter new”.
    • A blank “Name” field will now appear, along with it’s “value” field. In the “Name” field, type category-include.
    • In the “Value” field, type the category slug, e.g., “portraits”
      Over in the “Publish” column, click “Update” to save the page.

    Now the your category page has it’s shiny new custom field, “category-include”, set with your target category (the slug name, that is), go to the template.

    In the Template, itself, “Edit” the following:

    • Keep the line:
      <?php $values = get_post_custom_values("category-include"); $cat=$values[0]; ?>

      This will now look for the custom field, “category-include”, on any page
      which uses the template. Now the cat values make sense!

    • I changed portfoliocat to portfolio_category, as I’m on WP 3.5. Don’t know if they are interchangeable or not, as this is a first install, for me. But portfolio_category definitely works for me in the templates meant for the Portfolio pages. The code will look like this, exactly:
      <?php $catinclude = 'portfolio_category='. $cat ;?>

    That’s it! Hope this helps someone.

    Fran

    I have tested it with hardcoded category and subcategory values, as follows.

    But I’m not sure how to tie the pages and portfolio categories and templates all in a need bow, for a dynamic category. When I figure it out, I may re-post here.

    TEST w/ Hard-coded – category and subcategory values:
    Change:
    <?p $catinclude = 'portfoliocat='.$cat;?>
    To:
    <?p $catinclude = 'portfolio_category=PORTFOLIO_CATEGORY_SLUG'.$cat;?>

    …where “PORTFOLIO_CATEGORY_SLUG” is substituted with your category or subcategory already defined in Portfolio categories. Of course your test will be of categories that already have posts assigned to them.

    Tested on a top level portfolio category, “Paintings”, where the slug is “paintings”:
    e.g., <?p $catinclude = 'portfolio_category=paintings';?>

    Tested on a portfolio subcategory, “Portraits”, where the slug is “portraits”:
    e.g., <?p $catinclude = 'portfolio_category=portraits';?>

    Test passed! Results were only the categories showing that I wanted.

    However, I’m so new to WP that I don’t know my way around the relationships in the template system. It seems there would be a clear keyword for the category name.
    M4thieu’s ‘CATEGORY_NAME’ did not work for me though, and neither did the original code (as posted by the op, neonate928). $cat had no value. The $values array had no count. If these were not empty, hard-coding would no doubt not be necessary.

    My goal is actually the same as the op’s; and definitely with dynamic categories. I mean, that’s what templates are for. So I’ll keep plugging away until I see how to call these dynamically and give them the information they need to plug in that category for me.

    Hope this post helps someone along the way, though.

Viewing 4 replies - 1 through 4 (of 4 total)