• Resolved mukiri

    (@mukiri)


    I am trying to create custom markup with the plug in WordPress Popular Posts. If I do this through the admin panel it works fine!

    However, I am trying to do it directly in my custom theme template file with the function wpp_get_mostpopular(); in order to add classes etc.

    <?php wpp_get_most_popular($popular_posts_args);?>
    
    <?php $popular_posts_args = array (
    
    'header_start' => '<h2 class="widgettitle">',
    'header' => 'Popular Episodes',
    'header_end' => '</h2>',
    'limit' => 5,
    'range' => 'all',
    'title_length' => 25,
    'title_by_words ' => true,
    'post_type' => 'post',
    'cat' => '4',
    'excerpt_length' => 20,
    'thumbnail_width' => 100,
    'thumbnail_height' => 80,
    'wpp-start' => '<ol class="wpp-list">',
    'wpp-end' => '</ol>',
    'post_html' => '
    		<li class="clearfix">
    		<div class="wpp-content">
    		<div class="wpp-img">{thumb}</div>
    		<div class="wpp-text">{title}
    		<p class="wpp-stats">{stats}</p>
    		</div>
    		</div>
    		'
    );
     ?>

    This yields no changes to the default HTML markup that is generated by the function, but does create the widget and returns results.

    I went through the documentation and the plugin, and found a field called ‘custom__html’. I added it to the list of args and set it to true, no changes. Default HTML is generated.

    Spent a little more time looking through some more variables in the plugin file, found a couple more, so my $args variable became;

    <?php
      $popular_posts_args = array (
    	'header_start' => '<h2 class="widgettitle">',
    	'header' => 'Popular Episodes',
    	'header_end' => '</h2>',
    	'limit' => 5,
    	'range' => 'all',
    	'title_length' => 25,
    	'title_by_words ' => true,
    	'post_type' => 'post',
    	'cat' => '4',
    	'excerpt_length' => 20,
    	'thumbnail_width' => 100,
    	'thumbnail_height' => 80,
    	'custom_html' => true,
    	'markup' => array(
    		'wpp-start' => '<ol class="wpp-list">',
    		'wpp-end' => '</ol>',
    		'title-start' => '<h2 class="widgettitle">',
    		'title-end' => '</h2>') ,
    		'post_html' => '
    			<li class="clearfix">
    			<div class="wpp-content">
    			<div class="wpp-img">{thumb}</div>
    			<div class="wpp-text">{title}
    			<p class="wpp-stats">{stats}</p>
    			</div>
    			</div>
    			'
    		);
    	wpp_get_mostpopular($popular_posts_args);
    ?>

    And still no joy???

    My custom HTML parameters are ignored.

    Am i doing something wrong? Perhaps i am calling the wrong fields in order to create custom HTML?

    https://wordpress.org/plugins/wordpress-popular-posts/

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

    (@hcabrera)

    Hi, muriki!

    There’s a bug with the wpp_get_mostpopular() template tag when passing the parameters as an array which I never noticed before, so thanks for bringing this into my attention. This will be fixed on WPP 3.0.3.

    However, you had a few errors in your code:

    1. Function name is wpp_get_mostpopular, not wpp_get_most_popular.
    2. All parameters use underscore to separate words, not dashes: wpp-start should be wpp_start (yeah I know that in the code dashes are used, but that’s something users should not know).

    Workaround (with fixed params) until 3.0.3 is released:

    wpp_get_mostpopular("header_start='<h2 class=\"widgettitle\">'&header='Popular Episodes'&header_end='</h2>'&limit=5&range='all'&title_length=25&title_by_words=1&post_type='post'&cat=4&excerpt_length=20&thumbnail_width=100&thumbnail_height=80&wpp_start='<ol class=\"wpp-list\">'&wpp_end='</ol>'&title_start='<h2 class=\"widgettitle\">'&title_end='</h2>'&post_html='<li class=\"clearfix\"><div class=\"wpp-content\"><div class=\"wpp-img\">{thumb}</div><div class=\"wpp-text\">{title}<p class=\"wpp-stats\">{stats}</p></div></div>'");

    Thread Starter mukiri

    (@mukiri)

    OH!, I see what you did there!

    Thanks Hector,

    This workaround actually does work

    Cheers

    Thread Starter mukiri

    (@mukiri)

    Hello Hector,

    Finally updating my code, based on the update that now accepts arguments and this now appears to work just fine.

    Here is the code

    $popular_posts_args = array (
    			'header_start' => '<h2 class="widgettitle">',
    			'header' => 'Popular Episodes',
    			'header_end' => '</h2>',
    			'limit' => 5,
    			'range' => 'all',
    			'title_length' => 25,
    			'title_by_words ' => true,
    			'post_type' => 'post',
    			'cat' => '4',
    			'excerpt_length' => 20,
    			'thumbnail_width' => 100,
    			'thumbnail_height' => 80,
    			);
    
    		wpp_get_mostpopular($popular_posts_args);

    This works up until I try to pass in ‘markup’ parameter.

    $popular_posts_args = array (
    			'header_start' => '<h2 class="widgettitle">',
    			'header' => 'Popular Episodes',
    			'header_end' => '</h2>',
    			'limit' => 5,
    			'range' => 'all',
    			'title_length' => 25,
    			'title_by_words ' => true,
    			'post_type' => 'post',
    			'cat' => '4',
    			'excerpt_length' => 20,
    			'thumbnail_width' => 100,
    			'thumbnail_height' => 80,
    			'markup' => array(
    				'wpp-start' => '<ol class="wpp-list">',
    				'wpp-end' => '</ol>',
    				'title-start' => '<h2 class="widgettitle">',
    				'title-end' => '</h2>') ,
    			'post_html' => '
    					<li class="clearfix">
    						<div class="wpp-content">
    							<div class="wpp-img">{thumb}</div>
    							<div class="wpp-text">{title}
    								<p class="wpp-stats">{stats}</p>
    							</div>
    						</div>
    					</li>'
    			);

    The above code produces an error:

    ‘Warning: htmlspecialchars() expects parameter 1 to be string, array given in C:\wamp\www\Tujuane_Draft\wp-content\plugins\wordpress-popular-posts\wordpress-popular-posts.php on line 3000’

    In addition, I note that one can only pass categories as cat_ids.

    Is it possible to create the option of passing in the category by its category-slug? Reason I ask this, is I am developing my theme locally, and sometimes I cannot be sure if the same cat-ids are assigned to the same categories when they are created on the live site..

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘My custom markup ignored : Using Custom Markup with the wpp_get_mostpopular();’ is closed to new replies.