• Hi,

    I use the Secondary Title plugin to show the title of a post.

    Appreciate any help with this.

    I tried something like this.

    <?php
    $args = array(
        'limit' => 10,
        'range' => 'last24hours',
        'post_type' => 'album',
        'wpp_start' => '<div class="carouselLancamentos owl-carousel">',
        'wpp_end' => '</div></div>',
        'thumbnail_width' => 500,
        'thumbnail_height' => 500,
        'post_html' => '<div class="item"><div class="thumb"><div class="img" style="background-image:url({thumb_url});"></div></div>Your Custom Title Here (eg. {secondary_title})</div>'
    );
    wpp_get_mostpopular($args);
    ?>

    /**
    * Display the title and the publish date
    *
    * @param string $post_html
    * @param object $popular_post
    * @param array $instance
    * @return string
    */
    function my_custom_single_popular_post($post_html, $popular_post, $instance){
    $output = ‘

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @tom2,

    {secondary_title} isn’t a valid Content Tag. It doesn’t exist or at least WordPress Popular Posts doesn’t include it as it’s not a stock WordPress feature.

    You can register it as a custom Content Tag though by using the wpp_parse_custom_content_tags filter hook (but you’ll have to write the logic for this to work, don’t just copy & paste any code you see somewhere.)

    Thread Starter erismarcds

    (@tom2)

    I actually wanted to make the title appear. secondary title
    if you can help me thank you very much.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Alright, that link helped.

    This is what you need:

    /**
     * Parses custom content tags in WordPress Popular Posts.
     *
     * @param  string  $html    The HTML markup from the plugin.
     * @param  integer $post_id The post/page ID.
     * @return string
     */
    function wpp_parse_tags_in_popular_posts($html, $post_id){
    
        // Replace custom content tag {secondary_title} 
        // with the actual secondary title
        if (
            false !== strpos($html, '{secondary_title}')
            && function_exists('has_secondary_title')
        ) {
            // If the post has a secondary title, replace
            // the content tag {secondary_title} with
            // the secondary title
            if ( has_secondary_title($post_id) ) {
                $secondary_title = get_secondary_title($post_id);
                $html = str_replace('{secondary_title}', $secondary_title, $html);
            }
        }
    
        return $html;
    
    }
    add_filter("wpp_parse_custom_content_tags", "wpp_parse_tags_in_popular_posts", 10, 2);

    Add that code snippet to your theme’s functions.php file and you’re good to go.

    You’ll want to read the code to see what it does. This should help you understand a little better how PHP works in general.

    • This reply was modified 5 years, 9 months ago by Hector Cabrera. Reason: Fixed typo in code
    Thread Starter erismarcds

    (@tom2)

    if it is not too uncomfortable help me with this thing.

    I would also like to show the artists for each album.

    tried this more it worked.

    
    <?php
    
                      $songId = get_the_ID();
    
                      $artistaId = get_post_meta($songId, 'theme2035_album_artista_name', true);
    
                      if($artistaId != ""){
    
                        $get_artista_name = new WP_Query( array( 
    
                            'post_type' => 'artista',
    
                            'posts_per_page' => -1,
    
                            'p' => $artistaId,
    
                        ));
    
                        if( $get_artista_name->have_posts() ) : 
    
                            while( $get_artista_name->have_posts() ) : $get_artista_name->the_post(); 
    
                            $artista_name = get_the_title();
    
                            $artista_link = get_permalink();
    
                        endwhile;
    
                        endif;
    
                      ?>
    
    <a href="<?php echo esc_attr($artista_link); ?>"><?php echo esc_attr($artista_name); ?></a>
    
    /**
     * Parses custom content tags in WordPress Popular Posts.
     *
     * @param  string  $html    The HTML markup from the plugin.
     * @param  integer $post_id The post/page ID.
     * @return string
     */
    function wpp_parse_tags_in_popular_posts($html, $post_id){
    	
    	// Replace custom content tag {artista_name} 
        // with the actual secondary title
        if (
            false !== strpos($html, '{artista_name}')
            && function_exists('has_artista_name')
        ) {
            // If the post has a secondary title, replace
            // the content tag {artista_name} with
            // the secondary title
            if ( has_artista_name($post_id) ) {
                $artista_name = get_artista_name($post_id);
                $html = str_replace('{artista_name}', $get_artista_name, $html);
            }
        }
    
        // Replace custom content tag {secondary_title} 
        // with the actual secondary title
        if (
            false !== strpos($html, '{secondary_title}')
            && function_exists('has_secondary_title')
        ) {
            // If the post has a secondary title, replace
            // the content tag {secondary_title} with
            // the secondary title
            if ( has_secondary_title($post_id) ) {
                $secondary_title = get_secondary_title($post_id);
                $html = str_replace('{secondary_title}', $secondary_title, $html);
            }
        }
    
        return $html;
    
    }
    add_filter("wpp_parse_custom_content_tags", "wpp_parse_tags_in_popular_posts", 10, 2);
    Thread Starter erismarcds

    (@tom2)

    if possible how to add get_permalink (); on them

    Plugin Author Hector Cabrera

    (@hcabrera)

    For the artist thing, I’m sorry but you’ll have to do some research and try to figure it out on your own. I think I’ve already helped you plenty with stuff that’s not directly related to the plugin.

    Regarding the permalink, you can use the {url} Content Tag to obtain the URL of the post. You really should check the Content Tags documentation to see what’s available and save yourself some time (WP Dashboard > Settings > WordPress Popular Posts > Parameters, near the end of the page.)

    Thread Starter erismarcds

    (@tom2)

    I understand

    I can make a donation and you can help me with this, if possible, or how much you charge to do this.

    please

    Plugin Author Hector Cabrera

    (@hcabrera)

    Unfortunately offering/requesting paid jobs here in the forums is not allowed (see Forum Guidelines.) You may want to consider posting a job offer at WP Jobs to find someone who can lend you a hand with this.

    Thread Starter erismarcds

    (@tom2)

    sorry about that

    and thanks for helping me.

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

The topic ‘Secondary Title’ is closed to new replies.