WordPress.org

Ready to get started?Download WordPress

Forums

SortTable Post
Patch to allow specifying title for meta fields (9 posts)

  1. JB Christy
    Member
    Posted 2 years ago #

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. Or better still - use the pastebin ]

    I really like the SortTable Post plugin! One of the reasons I chose this plugin was support for custom post types and meta properties. However, I was little sad that the slug for meta properties is displayed to the user as the column heading. So I modified the code to allow specifying meta="field1|Title For Field 1,field2|Title For Field 2". I find this a very useful feature and I suspect other users might too. Perhaps you'd consider adding the feature to the next release of the plugin? If so, see the patch below (patch is relative to version 4.2 of the plugin).

    Thanks for a great plugin! Very handy!

    Index: sorttablepost.php
    ===================================================================
    --- sorttablepost.php	(revision 32)
    +++ sorttablepost.php	(working copy)
    @@ -102,8 +102,14 @@
     	if( !$opt_notitles == 'true' ) { echo '<th>Title</th>'; }
     	if( !$opt_nodates == 'true' ) { echo '<th>Date</th>'; }
     	if( !$opt_excerpts == '' ) { echo '<th>' . $opt_excerpts . '</th>'; }
    -	if( $opt_meta ) : foreach( $opt_meta as $key ) {
    -		echo '<th>' . $key . '</th>';
    +	if( $opt_meta ) : foreach( $opt_meta as &$key ) {
    +    list($field, $title) = explode('|', $key);
    +    if (!empty($title)) {
    +      echo '<th>' . sanitize_text_field($title) . '</th>';
    +      $key = $field;
    +    } else {
    +      echo '<th>' . $key . '</th>';
    +    }
     	} endif;
     	if( !$opt_nocats == 'true' ) { echo '<th>' . $catlabel . '</th>'; }
     	if( !$opt_notags == 'true' ) { echo '<th>' . $taglabel . '</th>'; }

    http://wordpress.org/extend/plugins/sorttable-post/

  2. polenisland
    Member
    Posted 1 year ago #

    Hi JBChristy!
    Your contribution is quite interesting but do not get it to work 100%.
    I changed the code of sorttablepost.php and the shortcode as you say.
    The custom titles of the headers is OK, but the custom fields parameters shows the first paramater in all columns.
    Do you know what happens? Could you help me?
    I hope I expressed myself clearly.

    Thank you very much!

  3. polenisland
    Member
    Posted 1 year ago #

    Sorry not the first paramaters in all columns, the last Custom Fields (Horas) shows the parameter of the penultimate (Cliente).
    If add other Custom Fields shows always the penultimate paramater.

    This is my code:

    [sorttablepost type="solares" meta="sol-referencia|Referencia,sol-potencia|Potencia,sol-cliente|Cliente,sol-horas|Horas" nothumb="true" nodate="true" nocats="true" notags="true"]

  4. JB Christy
    Member
    Posted 1 year ago #

    Hi, polenisland!

    Can you provide a URL where I can see the behavior? Also, if you could post the section of code you modified showing your modifications, that would help. I didn't author the plugin and I don't much about the code, but I'll try to take a look for you.

    -JB

  5. polenisland
    Member
    Posted 1 year ago #

    Hi JBChristy.
    I don't provide a URL because is an web aplication in a internal network.

    Here is the code i modified in sorttablepost.php:

    (Line 99)

    // Create table header row
    	echo '<table class="sortable" id="'. $opt_tableid .'"><tr>';
    	if( !$opt_nothumbs == 'true' ) { echo '<th class="sorttable_nosort"></th>'; }
    	if( !$opt_notitles == 'true' ) { echo '<th>Nombre</th>'; }
    	if( !$opt_nodates == 'true' ) { echo '<th>Date</th>'; }
    	if( !$opt_excerpts == '' ) { echo '<th>' . $opt_excerpts . '</th>'; }
    	if( $opt_meta ) : foreach( $opt_meta as &$key ) {
    	list($field, $title) = explode('|', $key);
    	if (!empty($title)) {
    	echo '<th>' . sanitize_text_field($title) . '</th>';
    	$key = $field;
    	} else {
    	echo '<th>' . $key . '</th>';
    	}
    	} endif;
    	if( !$opt_nocats == 'true' ) { echo '<th>' . $catlabel . '</th>'; }
    	if( !$opt_notags == 'true' ) { echo '<th>' . $taglabel . '</th>'; }
    	echo '</tr>';

    And this is the code which i add in page to show the table:

    [sorttablepost id="tablasolares" type="solares" meta="sol-referencia|Ref.,sol-tecnologia|Tecnología,sol-cliente|Cliente,sol-localizacion|Loc.Geográf.,sol-potencia|Pot.Pta(mW),sol-lazos|Núm.Lazos,sol-area-colectores|Área Col.(m²),sol-tipo|Tipo Col.,sol-area-planta|Área Pta.(m²),sol-temperatura|Temp.Vap.(ºC),sol-presion|Pres.Vap.(bar),sol-almacenamiento|Alm.Térm.,sol-tipo-almacenamiento|Tipo Alm.,sol-horas|Horas Alm.,sol-fecha|Fecha Contrat.,a| ,a| " nothumb="true" nodate="true" nocats="true" notags="true"]

    If not add the .,a| ,a| " at the end of code, the "sol-fecha" show the same of "sol-horas", but show two cells in blank at the end of the table.

    I hope you can help me...
    Many many thanks for your interest.

  6. JB Christy
    Member
    Posted 1 year ago #

    Hi, polenisland!

    I tried your shortcode on my system without the ',a| ,a| ' at the end. I don't have your data, but my column headings look fine. And your source code looks just like mine. I stepped through the code in the debugger and saw no problems.

    Here's the shortcode I used:

    [sorttablepost id="tablasolares" type="press" meta="sol-referencia|Ref.,sol-tecnologia|Tecnología,sol-cliente|Cliente,sol-localizacion|Loc.Geográf.,sol-potencia|Pot.Pta(mW),sol-lazos|Núm.Lazos,sol-area-colectores|Área Col.(m²),sol-tipo|Tipo Col.,sol-area-planta|Área Pta.(m²),sol-temperatura|Temp.Vap.(ºC),sol-presion|Pres.Vap.(bar),sol-almacenamiento|Alm.Térm.,sol-tipo-almacenamiento|Tipo Alm.,sol-horas|Horas Alm.,sol-fecha|Fecha Contrat." nothumb="true" nodate="true" nocats="true" notags="true"]

    And here's the HTML that was generated (formatted for easier reading):

    <table class="sortable" id="tablasolares">
      <tr>
        <th>Title</th>
        <th>Ref.</th>
        <th>Tecnología</th>
        <th>Cliente</th>
        <th>Loc.Geográf.</th>
        <th>Pot.Pta(mW)</th>
        <th>Núm.Lazos</th>
        <th>Área Col.(m²)</th>
        <th>Tipo Col.</th>
        <th>Área Pta.(m²)</th>
        <th>Temp.Vap.(ºC)</th>
        <th>Pres.Vap.(bar)</th>
        <th>Alm.Térm.</th>
        <th>Tipo Alm.</th>
        <th>Horas Alm.</th>
        <th>Fecha Contrat.</th>
      </tr>
    </table>

    I'm sorry, but I don't see the problem. The only thing I can think is maybe some un-printable character got in the meta list that prevented the explode() from recognizing the final | and it retained the previous value of $title. You might try deleting the last few columns (maybe from Tipo Alm. to the end) and retyping them.

    Wish I could be more help, but I'm afraid I can't reproduce your problem.

  7. polenisland
    Member
    Posted 1 year ago #

    Ok perfect, I'll continue trying to find the error.
    Many thanks, Sincerely....

  8. mschuyler
    Member
    Posted 1 year ago #

    I am having nearly the same issue except one difference - every column is correct except for the last.

    For example if my "field|title" is a|A,b|B,c|C - I enter the short code correctly but it displays as "a|A,b|B,b|C".

    Has anyone else ran into this problem? JB Christy or polenisland have you found a fix?

  9. coneff
    Member
    Posted 1 year ago #

    Hi, it's perfect idea, but i can't find a bug in the code.
    Display:

    a|A b|B c|C
    1,a 1,b 1,b
    2,a 2,b 2,b
    3,a 3,b 3,b

    I need:

    a|A b|B c|C
    1,a 1,b 1,c
    2,a 2,b 2,c
    3,a 3,b 3,c

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.