Forum Replies Created

Viewing 15 replies - 361 through 375 (of 1,041 total)
  • This worked for me

    <?php
    	$tit = get_the_title( $post->ID );
    	$arr = explode('|',$tit);
    	echo $arr[0];
    ?>

    Forum: Plugins
    In reply to: Document Repository

    Sorry for misunderstanding you. Are you referring to the “Meeting Agendas, Documents, and Minutes” section of the above site? If so, this can be done ( with a bit of custom code ) with WordPress.

    The simplest way would be to create a page hierarchy that looks somewhat like this:

    Documents
    – CAC Meeting Agenda
    – City Project Documents
    – Survey Results
    – (etc…)

    Each page under Documents would be a “child” page.

    Once the page hierarchy is complete, you will need to upload all of your files for each of the child pages through the media upload feature on each page.

    After your files are uploaded, you will want to create a Custom Page Template which will pull all attachments associated with the page that you apply it to. Each page listed under the Documents page will need this page template applied to it.

    Normally, when I am creating a page template like this, I will open the page.php file from my theme and save as under a new name.

    For your situation, you will want to use the get_children() function to return the files that you have uploaded. Please see the linked codex page for an example.

    Opps. There was a small oversight in my code. Please try this one:

    <a href="<?php print get_permalink( 3 ); ?>" id="nav-about" class="box_right_top">About Margaret</a>

    Thanks for the detailed answers!
    I’m beginning to grasp the concepts

    No problem, glad I could be of some help.

    Isn’t printing to the user client ‘Filtering’?

    Although this article at Wikipedia does not cite any sources, it has have this to say in regards to what a filter is:

    In chemistry and common usage, a filter is a device (usually a membrane or layer) that is designed to physically block certain objects or substances while letting others through.

    Basically, this implies that there is a something that exists which may contain objects or substances that are non-desirable for a certain purpose. In WordPress filters are used where something exists and we desire to change that something. Something is usually a piece of data… either a hard-coded variable in WordPress core or user supplied data that has been stored in the database. The key thing to remember is that filters almost always affect a piece of information. When you see plugin or theme code that uses add_filter() it is almost always applied to a function that returns a value and does not print, execute a query or anything like that.

    On the other hand actions are used mainly throughout the core to allow developers to add their own custom code at certain places in time. Take a look at the WordPress Action Reference where you will find a list of actions which are in place during a typical request. If a developer desires to print `<p>”HEY YOU GUYS!”</p>’ at the top of the sidebar, they can use the action hook ‘get_sidebar’ and add their function to the list of functions which fire at that given point in time.

    How is the context of printing custom css (Action function) different from the context of a Filter function?

    It is very important that you be able to recognize that in the filters example we changed data that already existed and in the actions example we printed data at a given point in time.

    Maybe this might help out. It’s a quick example of filtering that uses an array:

    function media_upload_tabs() {
    	$_default_tabs = array(
    		'type' => __('From Computer'), // handler action suffix => tab text
    		'type_url' => __('From URL'),
    		'gallery' => __('Gallery'),
    		'library' => __('Media Library')
    	);
    	return apply_filters('media_upload_tabs', $_default_tabs);
    }

    The above code was taken from line 16 of /wp-admin/includes/media.php and is the definition of a function whose sole purpose is to return an array. Notice that the apply_filters() function has been used in the return statement to allow developers to hook into and filter the value of the array. A developer could add or delete a key/value pair from the array if they were so inclined. They could make the function return false which would most likely disable navigation on the uploads screen… Basically freedom is given to alter the value of a certain piece of data.

    With simple action hooks, there is no data to alter therefore you are not changing anything you are using php to do something btw – sorry that I don’t have another way to say this other than ‘do something’ – I know it’s very vague 🙂

    Actually, in php there are a few elementary functions that do something: print -> outputs data to the screen, exit -> terminates execution of the script all together.

    These function do not alter data or return a value, they just do something -> which it what actions do as well.

    Just a simple php error, if you paste your code in the pastebin and post a link to it here, I’ll take a look and let you know what to do.

    Mark,
    This is most likely due to the fact that you have pasted the code outside of the <?php ?> tags. Please make sure that the code is placed before ?>

    This worked for me in WordPress 2.9.1 – Truth be told – this is somewhat of a hack and may need to be re-addressed when you upgrade.

    add_filter( 'ngettext', 'remove_theme_name_from_admin' );
    function remove_theme_name_from_admin( $c ) {
    	return ( strstr( $c, 'Theme <span class="b">%1$s</span> with <span class="b">%2$s' ) ) ? '' : $c;
    }

    Add the above code to your theme’s functions.php file

    Hi Betsy, I hope this explains everything!

    So, are filters a subset of actions?

    They are basically the same function applied to different contexts.

    If you take a peek into the core, you will see that add_action is actually a wrapper function for add_filter:

    function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
        return add_filter($tag, $function_to_add, $priority, $accepted_args);
    }

    it seems I could use an action to change the text of the post for instance, instead of a filter?

    Actually, you would use a filter for this situation. Let’s pretend that WordPress is a Mexican restaurant and we have ordered a taco as illustrated by the following code…

    <?php $taco = 'chicken'; ?>

    Basically, we have no choice… we will always be served a chicken taco. However, the same expression could be stated using the apply_filters() function. It is like ordering a taco and having the server ask you “well what kind of taco would you like?”

    <?php
    $taco = apply_filters( 'get_taco', 'chicken' );
    ?>

    The above code gives us access to the type of taco that we would like to have served. We can create a function which hooks into WordPress an changes the default value of $taco.

    <?php
    add_filter( 'get_taco', 'my_special_order' );
    function my_special_order( $content ) {
        return 'shredded beef';
    }
    ?>

    By adding the above code to you theme’s functions.php file or to a custom plugin, you are able to change the value of the variable $taco to whatever you like. Notice that the function “my_special_order” accepts one value. In this situation the value of $content is equal to the value of the second argument passed to the apply_filters() function. In this example it would be “chicken”.

    <?php
    add_filter( 'get_taco', 'my_special_order' );
    function my_special_order( $content ) {
        return $content . ' and avocado';
    }
    ?>

    The above code appends a string to the end of “chicken” resulting in a value of “chicken and avocado”.

    what would be a good example of correctly using filters while actions would be inappropriate for the situation?

    Basically, there usually is no choice for a plugin or theme developer as to which method they can use. The WordPress core is filled with calls to apply_filters() and do_action(). If I need to change the value of a piece of data, I will search through the core until I locate the file where that data is defined and see if it is possible to filter it’s value.

    If I need to do something at a certain time, I will look for calls to the do_action() hook. A simple example would be if I wanted to print custom css to the head of the document. I could easily add the following code to my theme’s functions.php file:

    <?php
    add_action( 'wp_head', 'print_my_custom_scripts' );
    function print_my_custom_scripts(){
        print '<style type="text/css">.red{color:#f00;}</style>';
    }
    ?>

    Notice how this time, the function did not return a value – it did something -> it printed text to the browser.

    Filters change data while actions allow us to do stuff.

    when should I use an action and when a filter?

    You would want to use an action where you need to do something at a certain point in time… add options to the database or print css or javascript.

    You should use a filter where you would want to alter the value of some data that WordPress has passed through the apply_filters() function.

    do the ‘hooks’ for actions and filters overlap? -can I add a either a filter or an action to the same hook?

    Actually, both filters and actions are hooks. That being said, the answer is “no”.

    The problem is that you have all of the links in the “right” div hard-coded in you html. You will want to use the get_permalink function.

    Instead of:

    <a href="http://www.domain.com/?page_id=3" id="nav-about" class="box_right_top">About Margaret</a>

    Use:

    <a href="<?php get_permalink( 3 ); ?>" id="nav-about" class="box_right_top">About Margaret</a>

    $thumb_id = get_post_thumbnail_id( $post->ID );
    if( !empty( $thumb_id ) )
    	print get_the_title( $thumb_id );

    David, glad it worked for you!

    JHouse, I just tested this out to verify and I was able to comment on posts on category views using the latest version of P2 on WordPress 2.9.1.
    Don’t know why it didn’t work for you -> did you click the “Reply” link on the post?

    Have you tried the function? I think that it will work for this situation. Try this and let me know if it works. I’m currently using this function in a project and it works beautifully for a similar situation.

    if( post_is_in_descendant_category( array( 25 ) ) ) {
    	/* Do Stuff Here... */
    }

    Mike, I’m wondering if your code goes completely in the functions.php file, or if the top part goes in the single.php while the “function” goes in function.php

    Yep, you got it!

    Forum: Plugins
    In reply to: multiple pools …

    What is a “pool”?

    I don’t think so.

Viewing 15 replies - 361 through 375 (of 1,041 total)