Block Widget to Appear in One Category

Posted in: Newspaper
Post count: 42

I would like a block widget to appear in only one category rather than sitewide. I have tried using an advanced widget but cannot work out the code to make my desired block and criteria appear.

The speific category is number 226.

Thx.

Dave

Post count: 6600

Hi,

You can use this code in loop.php file like this: http://screencast.com/t/lI3oL0TV0O6
Replace the ‘207’ with your category ID in which you would want the block to be showed. Also use the do_shortcode() function to add the block widget as you like, just replace the short-code from my example with your own.
Hope this helps!
Here is the code I used:

if  (is_category('226')) {
        echo do_shortcode('[vc_row][vc_column width="1/1"][td_block9 sort="random_posts" limit="5"][/vc_column][/vc_row]');
    }

Thanks

Post count: 42

Thansk Lucian. I’ve tried placing that code in an advanced widget but i get some errors appear. Do i need to place that code in a certain file to get it to appear in the Newspaper Default widget? Sorry for the no doubt very basic question! PHP isn’t my strong point!

Thanks.

Dave

Post count: 6600

Hi,

Please use http://pastebin.com/ to send me the code from loop.php file so I can check it, should work fine, I have tested this, you just need to add this condition in loop.php file and also add your widget short-code into the function and the category ID on which you want the widget to be shown.

Thanks

Post count: 42

Thanks Lucian. I may be doing something wrong. What should the widget code look like?

Loo.php attached. At the moment something odd happens at the bottom of the competitions section where it’s loading another section.

http://pastebin.com/t2qvJYns

You can see what I mean here – Under the comps it’s loaded some random posts from i’ve no idea where! : http://www.heyuguys.com/competitions/

D

Post count: 6600

Hi,

You have to replace this shortcode: http://screencast.com/t/aU7trBlMoEe with your own desired block shortcode then your block will appear there.

Thanks

Post count: 42

Aha! Could you give an example of some widget shortcode rather than code that will make something appear in the page itself?

So i need Block 2 to appear in the widget area inside category 226 only showing posts within that category.

Thx.

D

Post count: 6600

Hi,

Use page builder: http://screencast.com/t/PfhCn9Y0hzX and customize it like you want, then switch to classic mode view, get the shortcode for it: http://screencast.com/t/NX0r1MLZnfaE and replace the one from here: http://screencast.com/t/aU7trBlMoEe

Thanks

Post count: 42

Perfect, thanks so much and sorry for asking silly questions. You’ve been awesome.

So I’ve got the widget in, but for some reason nothing on it is clickable?!

http://www.heyuguys.com/competitions/

D

  • This reply was modified 11 years by daveszt. Reason: Updated
Post count: 6600

Hi,

I have checked your site, everything works fine, you can click the images/ titles/ “continue” button, all work fine.

Thanks for the message!

Post count: 42

Sorry if i wasnt clear. Go to the competitions section,

http://www.heyuguys.com/competitions/

See the new widget on the right hand side of the site which loads competitions in that section. That widget is not clickable.

http://www.heyuguys.com/widget.jpg

D

Post count: 6600

Hi,

You don’t need to add the block widget into an text widget like you did here: http://screencast.com/t/Hn48Ivn1S9VI
You just add the block into the sidebar and customize it, like this: http://screencast.com/t/56Uk7BaDor
Make sure you add the block the right way.

Thanks

Post count: 42

I think this is the issue though, i only want it to appear within one category, not site-wide.

D

Post count: 6600

Hi,

If you need that widget to appear only in that category follow this steps:

First remove the code I provided before to add an widget using short-codes, this code adds this block from the bottom of the category page: http://screencast.com/t/TH9vXkb1
After this create a new sidebar like this: http://screencast.com/t/qDp0rEFACe
Then go to appearance > widgets and add the block widget you want to the newly created sidebar, like this: http://screencast.com/t/bBb3sqdpzIS
After you have done all this go to theme panel > categories to the category you want to add the sidebar at and select the new created sidebar for that category only, like this: http://screencast.com/t/kwyygatOZ
Should work fine after this: http://screencast.com/t/J24VaBjRS

Thanks

Post count: 42

Fabulous, thanks so much.

Viewing 15 posts - 1 through 15 (of 15 total)
The forum ‘Newspaper’ is closed to new topics and replies.