2 of 2
2
Detecting a single entry using EE code
Posted: 20 August 2008 07:37 PM   [ Ignore ]   [ # 19 ]  
Summer Student
Avatar
Total Posts:  17
Joined  05-08-2008

I tried this but still it is not 100%. Perhaps we can push it there?

It seems that the first EXP loop will always leave behind an instance of pagination regardless whether or not it leaves any entry data behind. Do you know of a way to prevent this?

Otherwise we’re still back at square one where we are unable to tell the difference in EE between single-entries and weblog pagination as I am unable to find conditional that can tell the difference between “www.domain.com/weblog/entry_title” and “www.domain.com/weblog/P33”

Have you seen this executed successfully before? I am starting to doubt whether or not it is do-able aside from writing PHP code to do the work, which is not beyond do-able, just not ideal.

Thanks for your continued support!

 Signature 

http://www.poccuo.com

Profile
 
 
Posted: 28 September 2008 09:04 PM   [ Ignore ]   [ # 20 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2021
Joined  03-26-2006
Mason Kessinger - 20 August 2008 07:37 PM

Otherwise we’re still back at square one where we are unable to tell the difference in EE between single-entries and weblog pagination as I am unable to find conditional that can tell the difference between “www.domain.com/weblog/entry_title” and “www.domain.com/weblog/P33”

Mason, I haven’t used pagination much, but tonight I’m trying to do the exact same things as you: “getting conditional code that can detect whether or not {segment_3} is a pagination URL.”

I really want to use a single template for my pagination and the single entry, as it simply makes more sense from the layout of my sitemap/wireframe/mockup.

Here are the URLs as they work now:

http://www.site.com/items/ - a general page with featured entries, and a gigantic list of all items
http://www.site.com/items/P## - paginating through the huge list of the items
http://www.site.com/items/item/itemtitle/ - had to make a new template called ‘item’ to handle the single entry for this area

I absolutely can use a single template (as I’m doing elsewhere on the site) to handle the “landing page” for an area as well as the single-entry version of the page with a couple {if segment_3 != “”} and {if segment_3 == “”} conditionals. But when I introduce pagination, everything gets messed up. I would prefer my URLs for this area look like this:

http://www.site.com/items/ - same as above
http://www.site.com/items/P## - same as above
http://www.site.com/items/itemtitle/ - now using same template for pagination and single entry

Seems like a perfect opportunity to write a plugin to make a conditional based on whether the page is a pagination page or not. I’m with Mason on this - is a second template for a single entry the “approved” way to go here?

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 28 September 2008 09:28 PM   [ Ignore ]   [ # 21 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2021
Joined  03-26-2006

Mason, I think I just wrote a plugin that will figure this out. I’m testing it right now and will post here if I find that it’s working.

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 28 September 2008 10:10 PM   [ Ignore ]   [ # 22 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2021
Joined  03-26-2006

OK, I wrote a plugin for this. The thread for it is here: Plugin: MD Detect Page Type

You can download the plugin from here: MD Detect Page Type (at masugadesign.com).

Sample Usage:

{exp:md_detect_page_type url_segment="{segment_3}"}
  {
!-- if segment_3 is empty or it equals P## --}
  
{if pagination_page || segment_3 == ""}

    {
!-- list all the entries with pagination --}
    {exp
:weblog:entries weblog="weblog" paginate="bottom" limit="999"}
    
<h2>{absolute_count}. {title}</h2>
    <
p>{custom_field}</p>
    
{paginate}
    
<div class="pagination">
    <
p>Page {current_page} of {total_pages} pages. {pagination_links}</p>
    </
div>
    
{/if}
    {
/exp:weblog:entries}

  {
!-- otherwise, segment_3 has something in it
  
and it is not pagination. Show single entry --}
  {if
:else}

    {exp
:weblog:entries weblog="weblog" limit="1"}
    {if no_results}
<p>Sorry! Couldn't find that entry.</p>{/if}
    <h2>{title}</h2>
    <p>{custom_field}</p>
    {/exp:weblog:entries}

  {/if}
{/exp:md_detect_page_type}

I may not have hit every possible permutation of a pagination URL, but I’m using this right now, and it’s working for me…and eliminates an extra template.

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 29 September 2008 06:48 AM   [ Ignore ]   [ # 23 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  209
Joined  11-22-2006

I had some of these issues and found this thread with a solution by Robin Sowell.
It uses PHP and a regular expression to test if it’s a pagination link.

 Signature 

pfweb.co.uk

Profile
 
 
Posted: 29 September 2008 09:12 AM   [ Ignore ]   [ # 24 ]  
Summer Student
Total Posts:  13
Joined  07-15-2008

(logged in as wrong user, will repost)

Profile
 
 
Posted: 29 September 2008 09:18 AM   [ Ignore ]   [ # 25 ]  
Summer Student
Avatar
Total Posts:  17
Joined  05-08-2008

Ryan,

Always a pleasure to bump into you on these forums. I should have probably followed up with my final solution but you know how that goes. Here’s the gist of what I was able to accomplish and it works rather well for me.

<?php $entry = "{segment_2}"; ?>

<?php
if ($entry == ""): ?>
    
    
<p>You're looking at the section landing page.</p>
    
<?php elseif (preg_match("/^\d{4}$/",$entry)): ?>

    <p>You'
re looking at the section yearly archive.</p>

<?php elseif (preg_match("/category/",$entry)): ?>

    
<p>You're looking at a section category page.</p>

<?php elseif (preg_match("#^P(\d+)|/P(\d+)#",$entry)): ?>

    <p>You'
re looking at a pagination generated page.</p>

<?php else: ?>

    
<p>You're looking at a general entry page.</p>

<?php endif; ?>

Looks like its pretty close to where you were at, I just threw in a few more hooks for category pages, and date archives.

Since I’m relatively new to the PHP game I’d love to hear some feedback on if this. Maybe it would be good to work into your plugin? If you’re down I’d love to help or be a part of testing with you. A plugin like this could be a really cool asset.

 Signature 

http://www.poccuo.com

Profile
 
 
Posted: 29 September 2008 09:27 AM   [ Ignore ]   [ # 26 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2021
Joined  03-26-2006

Thanks for sharing what you worked out - looks useful! All the plugin really does in this case is keep PHP off the template. I’ll bet I could pretty easily update the plugin to incorporate your extra checks for different page types. The trick would be to make sure “category” wasn’t hardcoded into the plugin - because a user can change the designated category trigger word. I’d have to do the following, for example (totally sloppy and probably not correct, but you get the idea:

$category_word = $PREFS->ini("reserved_category_word");
elseif (
preg_match("/$category_word/",$entry)):

Because I can see this plugin helping me out on different builds, I may update it with these changes.

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 29 September 2008 10:28 AM   [ Ignore ]   [ # 27 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2021
Joined  03-26-2006

OK, I updated the plugin to include those other cases. Might help you keep your templates cleaner and safer because you’ll be able to turn PHP back off if this check was the only reason you were using PHP. I also changed the name from “MD Detect Pagination” to “MD Detect Page Type”, which is now more fitting. You can download the latest version here.

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 29 September 2008 10:40 AM   [ Ignore ]   [ # 28 ]  
Summer Student
Avatar
Total Posts:  17
Joined  05-08-2008

Wow, you truly are a master at this stuff. I can’t wait to try this out.

One question regarding your mention of using PHP in templates. I do find myself having to use extra PHP once in a while, but gather from your post that maybe its best to find a way around this? Do you try to eliminate activating extra PHP in your pages? Is it a significant waste of resources?

I’ve read up on the security reasons for this, but have not seen any documentation on performance issues. I’m curious to hear what you’ve got to say about this.

 Signature 

http://www.poccuo.com

Profile
 
 
Posted: 29 September 2008 10:48 AM   [ Ignore ]   [ # 29 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2021
Joined  03-26-2006

I don’t turn on PHP much for my templates, because there is usually a plugin out there for what I’m trying to do, and the PHP is so heinously ugly.

I do have to use PHP once in a while, which isn’t necessarily bad, but I just prefer to keep it off if I can help it. I’m not sure about any performance waste - if anything, I think the PHP would be taken care of quicker than EE tags, which have to be interpreted.

Keep in mind I studied oil painting in college and all this PHP stuff is trial by fire and trial n’ error with me! I’m just doing the best I can with it.

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 28 January 2009 06:08 PM   [ Ignore ]   [ # 30 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  740
Joined  10-14-2005

Hi Ryan, just stumbled into this plug-in, it’s awesome but… is there a way to have it work with categories when they are still being served using ‘C’ and the category id in the URL?

For example: http://www.example.com/blog/C13/

smile

 Signature 

Nathan Pitman - Nine Four

Follow me on Twitter - Try my EE plug-ins and extensions

Profile
 
 
Posted: 28 January 2009 07:04 PM   [ Ignore ]   [ # 31 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  740
Joined  10-14-2005

ok, well I think amending line number 50 to:

$conds['category_page'] = (preg_match('/^[C][0-9]+$/i', $url_segment)) ? TRUE : FALSE;

...seems to do the job.

 Signature 

Nathan Pitman - Nine Four

Follow me on Twitter - Try my EE plug-ins and extensions

Profile
 
 
Posted: 29 January 2009 10:07 AM   [ Ignore ]   [ # 32 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2021
Joined  03-26-2006

Thanks Nathan. Glad you were able to fix that. Couldn’t I just check for both category segment styles? Is that what you meant when you said you amended the line, rather than replaced the line?

$conds['category_page'] = (preg_match("/$category_word/", $url_segment)) ? TRUE : FALSE;
$conds['category_page'] = (preg_match('/^[C][0-9]+$/i', $url_segment)) ? TRUE : FALSE;
 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 29 January 2009 03:01 PM   [ Ignore ]   [ # 33 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  740
Joined  10-14-2005

hmm, yes that seems like a much better idea! smile

 Signature 

Nathan Pitman - Nine Four

Follow me on Twitter - Try my EE plug-ins and extensions

Profile
 
 
   
2 of 2
2
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 77557 Total Logged-in Users: 53
Total Topics: 101552 Total Anonymous Users: 25
Total Replies: 544387 Total Guests: 287
Total Posts: 645939    
Members ( View Memberlist )