Jump to content
Sign in to follow this  
AngelosTzelepis

PLOption not being applied when chosen from within page

Recommended Posts

AngelosTzelepis

I have created a custom section, which uses wp_query to pull out posts of a particular category only. The section is intended to be used on custom page templates. I have created an option for this, so that the user can choose the category of posts that should be displayed. The option is a simple dropdown containing the list of categories.

When I select a category from site wide options, it all works fine - only the posts in the chosen category are displayed. But when I select a category from the page options, it isn't applied. Here is my code:

Setting up the option in my section .php file:


function section_optionator( $settings ){

	 $settings = wp_parse_args( $settings, $this->optionator_default );

	 $array = array();

	 $categories = get_categories( $args );

	 $cat_arr = array();

	 foreach ($categories as $category) {

		 $cat_arr[$category->category_nicename] = array('name' => $category->cat_name);

	 }

	 $array['aamhc_post_loop_categories'] = array(

		 'type'			 => 'select',

		 'selectvalues' => $cat_arr,

		 'inputlabel'	 => __( 'Select Category:', 'pagelines' ),

		 'title'		 => __( 'Choose a category. Posts from this category will be displayed', 'pagelines' ),

		 'shortexp'		 => __( 'Choose a cetgory of posts to display', 'pagelines' ),

		 'exp'			 => __( "", 'pagelines' ),

	 );

	 $metatab_settings = array(

		 'id'		 => 'AAMHCPostLoopCat',

		 'name'		 => __( 'AAHMC Posts Loop (Category)', 'pagelines' ),

		 'icon'		 => $this->icon,

		 'clone_id' => $settings['clone_id'],

		 'active' => $settings['active']

	 );

	 register_metatab( $metatab_settings, $array );

}

Pulling out the option:

$cat_posts = new WP_Query();

$cat_posts->query('showposts=5&category_name=' . ploption('aamhc_post_loop_categories', $this->oset));

I had a look at the developer docs but the options section doesn't seem to be populated. Any help on how I can apply the option when selected from the page would be much appreciated.

Many Thanks,

John

Share this post


Link to post
Share on other sites
AngelosTzelepis

Hi Rob,

Thanks for getting back to me. I've pasted the following:

section.php

AAMHCPostsCategory (a supporting class, which extends pagelinesposts)

functions.php

Let me know if you need anything else.

Share this post


Link to post
Share on other sites
Rob

Well, we need the links to what you posted. There are tens of thousands of postings in the pastebin.

Sorry, I should have explained that.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
AngelosTzelepis

I have sussed this one out. I replaced $this->oset with an array and populated the items individually. Here is the old code:


function load_loop(){

	 $cat_posts = new WP_Query();

	 $cat_posts->query('showposts=5&category_name=' . ploption('aamhc_post_loop_categories', $this->oset));

I replaced it with the following:

function load_loop($this_id){


	 // Get the current page id

	 global $wp_query;

	 $thePostID = $wp_query->post->ID;


	 // Create the wp query object

	 $cat_posts = new WP_Query();


	 // Execute the query pulling in the option. Instead of using $this->oset, specify each element of the array individually, so that we can add the page id manually.

	 $cat_posts->query('showposts=5&category_name=' . ploption('aamhc_post_loop_categories', array(

		 'post_id' => $thePostID,

		 'clone_id' => NULL,

		 'group' => $this_id

	 )));

Share this post


Link to post
Share on other sites
mackenzie

Is this resolved? I couldn't tell from your last comments.


Mackenzie - PageLines Help Desk

The Centsible Family - Writer, Photographer and Coffee Addict

---------------------------------------------------

Kindly search this forum and read the documentation before posting. It will help you resolve many issues.

For CSS help be sure to check out W3Schools first and be sure to download FireBug for FireFox for troubleshooting.

Share this post


Link to post
Share on other sites
AngelosTzelepis

Yes, it's working now. Thanks.

Share this post


Link to post
Share on other sites
mackenzie

The topic was marked as resolved.


Mackenzie - PageLines Help Desk

The Centsible Family - Writer, Photographer and Coffee Addict

---------------------------------------------------

Kindly search this forum and read the documentation before posting. It will help you resolve many issues.

For CSS help be sure to check out W3Schools first and be sure to download FireBug for FireFox for troubleshooting.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • Audun MB
      By Audun MB+
      I've added a number option (ie the first box has a 1 next to or above, second box has 2, etc) to iBoxes in DMS (as a custom section), and I'd like that for PL5 Boxes as well. Adding it for iBox was quite easy:
      First this: 'opts' => array( 'icon' => array( 'name' => __( 'Icon Font', 'pagelines' ) ), 'count' => array( 'name' => __( 'Counter', 'pagelines' ) ), 'image' => array( 'name' => __( 'Images', 'pagelines' ) ), 'numb' => array( 'name' => __( 'Number', 'pagelines' ) ), 'text' => array( 'name' => __( 'Text Only, No Media', 'pagelines' ) ) And then this } elseif( $media_type == 'numb' ){ $background = ($color) ? sprintf('<span class="invert-icon" style="background-color: %s;"></span>', $color) : ''; $media_html = sprintf( '<i class="iii icon iboks-number" style="%s">%s</i>%s', $text_color, $count, $background ); } And some CSS (though I used the style for icon mostly). iBox already did know which number the box had in the sequence, so adding the number was quite simple. 
      The Boxes code, and PL5 code in general, is a bit mor complex with javascript (with Knockout) and php, and some CSS cheats. It took me a while to figure out how it works, and I'm not sure I quite grasp it yet.
      Adding a number option to the media array is the same as iBox:
      array( 'key' => 'ibox_media', 'type' => 'select', 'opts' => array( 'icon' => array( 'name' => __( 'Icon Font', 'pl-section-boxes' ) ), 'count' => array( 'name' => __( 'Counter', 'pl-section-boxes' ) ), 'boxnumb' => array( 'name' => __( 'Numbering', 'pl-section-boxes' ) ), 'image' => array( 'name' => __( 'Images / SVG', 'pl-section-boxes' ) ), 'text' => array( 'name' => __( 'Text Only, No Media', 'pl-section-boxes' ) ) ), 'default' => 'icon', 'label' => __( 'Select iBox Media Type', 'pl-section-boxes' ), ), In the section template I'll add a line for the boxnumber. In addition I have to add variuous boxnumb classes in the build.less file to make it hidden by default and style it.
      function section_template(){ ?> <script type="text/html" id="boxes-template"> <a class="boxes" data-bind="class: boxclass() + ' pl-col-sm-' + $root.ibox_cols(), plhref: link" > <div class="boxes-pad" data-bind="class: 'pl-control-'+ $root.ibox_format()"> <div class="boxes-media media-left"> <span class="the-boxes-media pl-animation pl-appear" data-bind="class: 'media-'+$root.ibox_media(), style: { color: color, width: $root.image_width() + 'px', opacity: $root.image_opacity}"> <div class="pl-image" data-bind="plbg: image, class: $root.image_format"></div> <span class="pl-counter" data-bind="pltext: count"></span> <span class="pl-boxnumb" data-bind="pltext: ?numbervalue?"></span> <i class="boxes-icon pl-icon" data-bind="class: 'pl-icon-'+icon()"></i> </span> </div> <div class="boxes-text media-right"> <h3 class="boxes-title" data-bind="pltext: title"></h3> <div class="boxes-desc" data-bind="pltext: text"></div> </div> </div> </a> </script> Where I'm stuck is how to get the number to supply to pltext. Since the boxes are numbered in the configuration panel (showing as Item 1, Item 2, ...) I guess there is something in the code that could give me the box number, but what would that be? Finding it in the pure php code of iBox was quite easy, but the Javascript-Knockout.js-PHP code in PL5 isn't that easy to read. 
      I realise that I'm developer terrority now, but I'd appreciate any help. I guess this could be useful for more people if get it to work. Maybe it should be added as a standard option? "X things you need to know" or similar is staple website content and the Boxes section is ideal for that with numbers. On our website the "X things you need to know"-pages is half our traffic. 
    • janpeeters
      By janpeeters
      Over the last month I had extensive communications with the developer of the (premium) Anything Boxes section (in Pagelines store) (Adam Munns) and the developer of the WP Polylang Multilingual plugin (Frederic Demarle).
       
      This was because the following problem occurred:
      Anything Boxes showed all posts of two languages (Dutch and English) on the respective static frontpages for each language. It should of course have filtered posts for Dutch language on the Dutch frontpage and English on the English frontpage.
       
      The solution to this problem was simple in the end. When duplicating a page for use in another language the settings for Anything Boxes were not copied to the new page and I should have set these settings manually again on the new page. I wasn't aware of this, but it makes sense. Because of this the pages didn't know how to differentiate between posts from different languages.
       
      The dev of Polylang told me that Polylang is currently smart enough to synchronize metas like Featured images and page templates but it does not work out of the box with metas created by plugins and themes but (according to Frederic) it is rather easy to add them in the list using the filter 'pll_copy_post_metas'.
      He mentions that he is not sure that these 'PageLines Meta Settings' are stored in post meta but that would make sense according to him. He asks if the Pagelines dev team will be interested to support this feature in the future.
       
      I'm also wondering if you will consider adding Polylang translation support for manually editable strings like the 'Read more…' strings in Pagelines Settings.
       
      Well that's of course up to you but I thought to let you know to be able to take this into consideration. I also post this for other users in case they experience the same kind of trouble and are looking for an answer.
       
      Best regards,
      Jan Peeters
    • bankrollbuilder
      By bankrollbuilder
      I used a custom hook to put a banner ad in my header. It works but its not in the right position. it is centered and above my logo and I would like to float it to the right of my logo in the header. heres the link: http://shaboopie.com/shaboopie-wp/free-logos-pg1/

      thanks.

      Dan B.
    • starlit
      By starlit
      Can one have two hero sections on one page?

      I want a landing page which leads/advertises two subpages.

      Or is there another option?

      Please help.

      THANK YOU
    • hutruk
      By hutruk
      Hi!

      I am using the shortcodes for tabs, as described in the documentation.

      When I insert the following code:


      [pl_tabs][pl_tabtitlesection type="tabs"] [pl_tabtitle number="1"]Title 1[/pl_tabtitle] [pl_tabtitle number="2"]Title 2[/pl_tabtitle] [/pl_tabtitlesection] [pl_tabcontentsection] [pl_tabcontent active="yes" number="1"] Lorem ipsum dolor sit amet, consectetur adipiscing elit [/pl_tabcontent] [pl_tabcontent number="2"] Lorem ipsum dolor sit amet, consectetur adipiscing elit [/pl_tabcontent] [/pl_tabcontentsection] [/pl_tabs]

      I get a strange output (in the attachment).

      Any ideas?

      Thanks in advance!

×