Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#61 2012-01-11 22:34:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: smd_featured: Quickly pull articles to your home / landing pages

rossharvey wrote:

If I need to store them permanently, the easiest thing to do would be to keep a text file with article ID and custom description.

Yeah, or re-labelling them with an ‘archive’ label.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#62 2012-01-11 22:42:26

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

Re: smd_featured: Quickly pull articles to your home / landing pages

Ah yes, that would work perfectly. Thanks :¬)

Edit: It does work perfectly. Only need add the ‘live’ label to the true article to feature. Thanks!

Last edited by rossharvey (2012-01-11 23:00:02)

Offline

#63 2012-04-09 03:13:54

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_featured: Quickly pull articles to your home / landing pages

As txp:if_first_article was “failing” (always returning true) inside a smd_featured loop, I took a peak at the plugin’s source code.
As I’m a very clever guy, I already suspected that the plugin may be using some trickery involving article_custom to output the articles. But I’m not that clever to understand it properly and hack it.
So, if I get it right, smd_featured calls article_custom once for each featured article, and that may be the reason for tags like if_first_article to fail, as each article is always the first article on this just-one-loop iterations.

To workaround this issue, I’m doing the nasty (and clever, did I said I’m clever?) trick of using smd_featured to create a comma-separated list of featured article IDs, storing them in a txp:variable, and then feeding that variable to article_custom (via its id attribute).
But I wonder if this can be solved, in a similar fashion, directly in the plugin’s code.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#64 2012-04-09 03:51:37

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_featured: Quickly pull articles to your home / landing pages

Bonus request:
you may want to consider updating the value for last modification after featuring/unfeaturing an article.
This is helpful when using plugins like aks_cache, to cache queries like the ones done by smd_featured.
This worked for me:

  function smd_featured_tagit() {
  	global $smd_featured_event;
  	extract(doSlash(gpsa(array('smd_feat_id', 'smd_feat_action'))));

  	assert_int($smd_feat_id);

  	if ($smd_feat_action == 'add') {
  		$ret = safe_upsert(SMD_FEAT, "label=''", "feat_id='$smd_feat_id'");
  	} else if ($smd_feat_action == 'remove') {
	  	$ret = safe_delete(SMD_FEAT, "feat_id='$smd_feat_id'");
	  }
+  	update_lastmod();
  }

Then, I couldn’t find how to apply a similar hack when updating the position value.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#65 2012-04-09 04:35:41

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_featured: Quickly pull articles to your home / landing pages

And also, I’d suggest to trigger update_lastmod() at the end of smd_featured_save(). If not, the lastmod won’t get updated when labelling/unlabelling (or adding/removing info) on a featured article.

I’ve tested both changes and it seemed to work flawlessly, but then, I’m just a hacker-wannabe.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#66 2012-04-29 09:36:02

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: smd_featured: Quickly pull articles to your home / landing pages

Found out that for me, the limit="3" attribute on the smd_featured is not working. There is no output when I add the limit as follows:

<div class="featured clearfix">
	<txp:smd_featured limit="3">
		<div class="meta">
			<txp:permlink>
			<txp:if_article_image>
				<txp:images limit="1" break="" sort='field(`ID`,<txp:custom_field name="article_image" />)'>
					<txp:smd_if_thumbnail type="medium">		
						<txp:smd_thumbnail type="medium" />							
					</txp:smd_if_thumbnail>
				</txp:images>
			</txp:if_article_image>
			<div class="description">
				<p><txp:title /></p>
			</div><!-- close description -->
			</txp:permlink>
		</div><!-- close meta -->	
	</txp:smd_featured>	
</div><!-- close featured -->

Take out the limit attribute and all works fine. Had the issue on 0.40 so upgraded to 0.4.1, same behaviour I’m afraid. The above code is on the default page template.

Offline

#67 2012-04-30 22:25:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: smd_featured: Quickly pull articles to your home / landing pages

jstubbs wrote:

Found out that for me, the limit="3" attribute on the smd_featured is not working

Weird, not sure what to suggest here. Your exact code shows 3 articles on my test site and if I alter the limit attribute (or remove it) I get the requisite number of articles displayed.

I assume your articles are all published in the past. Does it matter if you specify the label or not? Are they in fact labelled at all? Are there any telltale errors in your log files or debug production mode that might give us a clue what’s going on here? Maybe something’s breaking behind the scenes.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#68 2012-05-01 06:59:17

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: smd_featured: Quickly pull articles to your home / landing pages

Hi Stef,

No labels on the featured articles – just a plain old selection of 3 articles. Because this site runs MLP with 3 languages, that means 9 articles were selected.

Nothing in debugging either that stuck out, here is the debugging output with the attribute limit="3" and limit="3" label="".

<txp:smd_featured limit="3">
	[SQL (0.00025010108947754): select feat_id from smd_featured where 1=1]
	[SQL (0.0025570392608643): SELECT *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod FROM textpattern AS txp LEFT JOIN smd_featured AS smdfeat ON txp.ID=smdfeat.feat_id WHERE smdfeat.feat_id IN ('156','1559','2194','2789','2794','2795','2911','2912','3151','3152','3153') AND Posted <= now() AND (now() <= Expires OR Expires = '0000-00-00 00:00:00') AND Status IN (4,5) ORDER BY feat_position asc, Posted desc LIMIT 3]
	[<txp:smd_featured limit="3">: true]
	[<txp:smd_featured limit="3">: false]
	[SQL (0.00054216384887695): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from l10n_txp_en_gb where 1=1 and Status >= 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and ID IN (2911) order by Posted desc limit 0, 3]
	[SQL (0.00063514709472656): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from l10n_txp_en_gb where 1=1 and Status >= 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and ID IN (2794) order by Posted desc limit 0, 3]
	[SQL (0.0005040168762207): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from l10n_txp_en_gb where 1=1 and Status >= 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and ID IN (2912) order by Posted desc limit 0, 3]
</txp:smd_featured>
<txp:smd_featured limit="3" label="">
	[SQL (0.0021898746490479): SELECT *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod FROM textpattern AS txp LEFT JOIN smd_featured AS smdfeat ON txp.ID=smdfeat.feat_id WHERE label='' AND Posted <= now() AND (now() <= Expires OR Expires = '0000-00-00 00:00:00') AND Status IN (4,5) ORDER BY feat_position asc, Posted desc LIMIT 3]
	[<txp:smd_featured limit="3" label="">: true]
	[<txp:smd_featured limit="3" label="">: false]
	[SQL (0.00054001808166504): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from l10n_txp_en_gb where 1=1 and Status >= 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and ID IN (2911) order by Posted desc limit 0, 3]
	[SQL (0.00048589706420898): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from l10n_txp_en_gb where 1=1 and Status >= 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and ID IN (2794) order by Posted desc limit 0, 3]
	[SQL (0.00049304962158203): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from l10n_txp_en_gb where 1=1 and Status >= 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and ID IN (2912) order by Posted desc limit 0, 3]
</txp:smd_featured>

Offline

#69 2012-05-01 08:51:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: smd_featured: Quickly pull articles to your home / landing pages

jstubbs wrote:

this site runs MLP

Ah, right. Should have guessed :-)

Thanks for the debugging output. That helps a lot. Where you see those 3 SQL statements in a row towards the end, they should be interspersed with stuff like this:

[article 2911]
...
	<txp:permlink>
		<txp:title />
	</txp:permlink>
...

Once you see that type of construct, it means it’s found the article. In this case, it’s not finding the article so we need to figure out why.

Now, the difference between your 3 queries and mine is that mine don’t reference the l10_ tables because I don’t have MLP. So my guess is something is getting in the way as MLP is rewriting the queries.

You may need to do some sleuthing. See the 3 articles it pulls out: 2911, 2794, and 2912? It’s looking for those in the l10n_txp_en_gb table so it’s assuming the first three articles are English. My gut feeling is that these 3 article are in fact not English so it’s looking in the wrong place. The English IDs are probably further down the list but it never reaches them because of the limit. If you check your database you’ll probably find that’s the case. And in fact if you switch languages you’ll probably find you get some (or all) of the articles displayed when you find the language that corresponds to one or more of those article IDs.

As a temporary (untested) workaround, if you were to up the limit to 9, you’d probably see the output correctly because it’ll pull out all the articles from all languages then look for each one in the currently selected language table. Of course, it’ll only find 3 of them that match, so you’ll only see 3 as expected.

It’s a counter-intuitive hack but I think it’ll do the trick. If it works, the rule is that if you’re using limit and MLP with this plugin, multiply the desired limit by the number of installed languages and use that value instead! I might be able to come up with a work-around in the plugin but I’m not sure at this stage.

Hope that helps.

Last edited by Bloke (2012-05-01 08:54:04)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#70 2013-03-07 11:01:23

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: smd_featured: Quickly pull articles to your home / landing pages

Hi Stef,
there’s the possibility to integrate smd_featured with MLP?
What I do is label each article with language abbreviation and use l10n_if_lang to view article by lang.
I think that automate this procedure is a big implement for smd_feature. Like the possibility to filter article by lang in the plugin admin tab.
What do you think?

Offline

#71 2013-05-31 20:14:39

floodfish
Member
From: Brooklyn, NY
Registered: 2007-01-11
Posts: 155
Website

Re: smd_featured: Quickly pull articles to your home / landing pages

Hi Stef,

I recently upgraded a site to 4.5.4 and now smd_featured is no longer accepting sort values (per each box). You can type a value in the box, but it is not saved/used.
Any ideas why that might be or how we might fix it?

Offline

#72 2013-06-02 20:59:46

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: smd_featured: Quickly pull articles to your home / landing pages

floodfish wrote:

smd_featured is no longer accepting sort values (per each box).

Have you tried the beta which is 4.5.x compatible? The plugin needs to be of “type 5” which should be set if you upgrade to that version. I re-uploaded it just now in case it wasn’t set beforehand.

Last edited by Bloke (2013-06-02 21:00:42)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB