Expression Engine - Help with category entries - php

OK, I have set up channel for the client to add projects. The way it works is simple:
I have a category page that displays all of the projects from the chosen category.
I then have a title_permalink page that displays a project, on this page there are 6 most recent related projects that are from that category, each linking to a projects/view page. On this page it displays the project and again, the SAME 6 most recent related projects.
I need to change the 6 recent related projects to be 6 PREVIOUS projects (from the category) dependant on which project has been chosen? For example, I have 20 projects sorted by date entered, I click on number 11 which was entered on Friday at 09:30. I need the view page to display the PREVIOUS 6 projects (by date&time) dependant on which project page you are on.
I have searched high and low but haven't found any help. I'm not asking someone to give me the answer. I just need pointed in the right direction as to the right solution for this.
The code for my project (title_permalink) page is:
<div id="projectView">
{exp:channel:entries channel="project"}
{exp:imgsizer:size src="{project_image}" width="980px" height="450px"}
<img src="{sized}" width="{width}" height="{height}"/>
{/exp:imgsizer:size}
<div id="projectView_overlay"></div>
<div id="projectView_content">
<h3>{title}</h3>
<p class="projectView_floatLeft"><b>Client:</b> {project_client} – <b>Value:</b> £{project_value} – <b>Duration:</b> {project_duration} weeks – <b>Architect:</b> {project_architect}</p>
<p class="projectView_floatRight" style="color:#fff; font-size: 12.5px; font-weight:bold; margin-bottom: 5px;">{categories}<< Back to<br />{category_name}{/categories}</p>
</div>
{/exp:channel:entries}
<br style="clear:both"/>
</div><!--END PROJECT VIEW-->
<ul id="filmStrip">
{exp:channel:entries start_on="{entry_date format="%Y-%m-%d %H:%i"}" channel="project" limit="6" category_group="1" related_categories_mode="yes" custom_fields="yes"}
<li>
{exp:imgsizer:size src="{project_image}" height="68px" width="137px"}
<img src="{sized}" height="{height}" width="{width}" alt=""/>
{/exp:imgsizer:size}
<p class="thumbTitle">{title}</p>
</li>
{/exp:channel:entries}
</ul><!--END FILM STRIP-->
Thanks for any help!

There is a parameter for the channels tag called start_on=[DATE]. I suggest you grab the entry date from the project you want to pull entries before, then use that date in your related entry tag. Note, you are using a variable {exp:channel:entries} to populate another channel:entries tag so it will always pull the projects you want - you are not hardcoding it.
{exp:channel:entries} // This tag gets your single project data
//output your project details here
{exp:channel:entries start_on="{entry_date format="%Y-%m-%d %H:%i"}" channel="project" limit="6" category_group="1" related_categories_mode="yes" custom_fields="yes"} // this tag grabs the last six projects relative to the single project being displayed
{make your links to the projects here}
{/exp:channel:entries}
{/exp:channel:entries}
You need to use the format YYYY-MM-DD HH:MM, as above.

The one flaw in Dan's answer is that he's nesting two channel:entries tags. That can lead to disaster. You need to embed the "related" template. Also, I think you want stop_before, not start_on. Try this modified code:
<div id="projectView">
{exp:channel:entries channel="project"}
{exp:imgsizer:size src="{project_image}" width="980px" height="450px"}
<img src="{sized}" width="{width}" height="{height}"/>
{/exp:imgsizer:size}
<div id="projectView_overlay"></div>
<div id="projectView_content">
<h3>{title}</h3>
<p class="projectView_floatLeft"><b>Client:</b> {project_client} – <b>Value:</b> £{project_value} – <b>Duration:</b> {project_duration} weeks – <b>Architect:</b> {project_architect}</p>
<p class="projectView_floatRight" style="color:#fff; font-size: 12.5px; font-weight:bold; margin-bottom: 5px;">{categories}<< Back to<br />{category_name}{/categories}</p>
</div>
<br style="clear:both"/>
</div><!--END PROJECT VIEW-->
{embed="projects/related" stop_before="{entry_date format="%Y-%m-%d %H:%i"}"}
{/exp:channel:entries}
And projects/related looks like:
{exp:channel:entries channel="project" limit="6" category_group="1" stop_before="{embed:stop_before}" related_categories_mode="yes" custom_fields="yes"}
{if count == "1"}<ul id="filmStrip">{/if}
<li>
{exp:imgsizer:size src="{project_image}" height="68px" width="137px"}
<img src="{sized}" height="{height}" width="{width}" alt=""/>
{/exp:imgsizer:size}
<p class="thumbTitle">{title}</p>
</li>
{if count == total_results}</ul>{/if}
{/exp:channel:entries}

Related

PHP echo printing outside of my html bounds

I'm making a website where users can post stories etc and they get put into the MySQL database and the front page pulls the top-rated stories from the database and fills in the HTML template I made to display.
So I pull the top rated post and put it inside the article tags that I've made inside my HTML. The question is when it displays it displays outside of the box. Like so
The actual display is supposed to look like this
How do I format the PHP code, Or is there some better way to go about doing this?
<article class="post featured">
<header class="major">
<span class="date">April 25, 2017</span>
<h2>
And this is a<br />massive headline
</h2>
<?php echo '<p>' . htmlspecialchars($row['post'], ENT_QUOTES, 'UTF-8') . '</p>'; ?>
</header>
<img src="images/pic01.jpg" alt="" />
<ul class="actions special">
<li>Full Story</li>
</ul>
<span class="tags badge-pill badge-primary">Otero</span>
<span class="tags badge-pill badge-info">SCR</span>
<span class="tags badge-pill badge-success">Class of '22'</span>
<span class="tags badge-pill badge-danger">Male</span>
</article>
EDIT: Here is the HTML spot I'm talking about
Ok, It`s easy to solve. First your string has only one word (because doesn´t have spaces) an second, when you have a paragraph, the tag that wrap content has an autoalignement.
Maybe you can try adding some css rules for your parent div?
You may check this : https://stackoverflow.com/a/3367759/8186765

PHP Simple HTML DOM Parser - find function not working with multiple classes

I am trying to parse a certain section out of a website. I know my cURL statement is working and grabbing the raw HTML, because I can echo the results of the cURL command and see the web page contents on my server.
Here is what I am trying to parse out:
As you can see I am trying to parse out the "mw-scrollable-news.collection.j-tabPane.is-active.j-scrollViewport".
My code looks like this, I am using the exact CSS selector as is given on the site:
$html = str_get_html($results); // $results is the results of the cURL
$articleDivArray = $html->find('mw-scrollable-news.collection.j-tabPane.is-active.j-scrollViewport');
However when I do a:
print_r($articleDivArray);
It brings back an empty:
array(0) {
}
Here is what the raw HTML looks like:
<div class="collection__list j-scrollElement" data-type="Other" data-showTimestamp="True" data-showImage="False" data-showProvider="True" data-showByline="False" >
<div data-docid="1341791639" class="element element--article no-image j-scrollByElement">
<div class="article__content">
<h3 class="article__headline"><a class="link" rel="nofollow" target="_blank" data-source="seekingalpha.com" href="https://seekingalpha.com/news/3392514-new-age-beverages-enters-market-offering-agreement?source=marketwatch">New Age Beverages enters into At the Market Offering Agreement</a></h3>
<p class="article__summary">New Age Beverages enters into At the Market Offering Agreement</p>
<ul class="article__details">
<li data-est="2018-09-24T13:51:00" class="article__timestamp">Sep. 24, 2018 at 1:51 p.m. ET</li>
<li class="article__provider">on Seeking Alpha</li>
</ul>
</div>
</div>
<div data-docid="1341775218" class="element element--article no-image j-scrollByElement">
<div class="article__content">
<h3 class="article__headline"><a class="link" rel="nofollow" target="_blank" data-source="fool.com" href="https://www.fool.com/investing/2018/09/24/big-highs-wont-last-for-new-age-beverage-stock.aspx?source=djc&utm_campaign=article&utm_medium=feed&utm_source=djc">Big Highs Won't Last for New Age Beverage Stock</a></h3>
<p class="article__summary"></p>
<ul class="article__details">
<li data-est="2018-09-24T09:00:00" class="article__timestamp">Sep. 24, 2018 at 9:00 a.m. ET</li>
<li class="article__provider">on Motley Fool</li>
</ul>
</div>
and so on etc...
Am I doing something wrong?

Preg matching random text from html source code using PHP

I have website and it's source html code looks something like below.
<li class="item" xx-href-xx="http://xx.xx/s/randomtext/randomtext?NOTradnomtext" yy-href-gg="http://xx.xx/X/RANDOMTEXTWHATIWANT/STILLRADNOMTEXTWHATIWANT?NOTradnomtext" data="212123134" data-title="TITLE">
<a class="front" href="#" xx-href="http://xx.xx/s/randomtext/randomtext?NOTradnomtext">
<img src="http://photo.jpg" alt="">
<div class="cock">
<div class="action"></div>
</div>
</a>
<div class="label">
<div>
<h3 class="title">Example</h3>
<p>2013-10-25 : 03:35</p>
</div>
</div>
</li>
... And so on same kind of classes (only titles and texts changing) ...
How to preg_match yy-href-gg="http://xx.xx/X/TEXTWHATIWANT/TEXTWHATIWANT?NOTradnomtext from all of those records and include also title for result. So result should look in this case something like that
Example
TEXTWHATIWANT/TEXTWHATIWANT
Example2
TEXTWHATIWANT/TEXTWHATIWANT
and so on.
Sorry if my post is little bit unclear, I should to go sleep..

highlight current page menu li

Is there a way for me to highlight a menu li depending on the page id? I can't seem to figure out a way to do it.
http://www.dawaf.co.uk/cthm/work/
<div id="header">
<h1>
<a href="http://www.dawaf.co.uk/cthm/work">
<img src="http://www.dawaf.co.uk/cthm/wp-content/uploads/2013/01/logo2.png" alt="CTHM Logo" id="logo" width="140" height="44" />
</a>
<div id="contact-details">
26 Queen Anne Road, London, E9 7AH<br />
t + 44 7912325101<br />
hello#cthm.co.uk
</div>
</h1>
<div id="nav">
<span id="nav-li">
Work
Studio
CTHM+
<a href="https://twitter.com/hello_cthm" target="_blank">
<img src="http://www.dawaf.co.uk/cthm/wp-content/uploads/2013/01/twitter.png" alt="Twitter" width="13" height="13">
</a>
</span>
</div>
</div>
<div id="content">
I would recommend adding an active class to the navigation item. Something like this:
Work
And then the CSS:
#nav a.active {
/* your active style here */
}
You have two options. One is that mentioned by Zak, whereby you would need to use jQuery for your website to mark only one item at a time as "active". The other option is the CSS :active selector, which will auto apply CSS to the link which is in use (at the present time). For example:
#nav li a:active {
/* Insert styling here, such as, background-color: #01B */
}
Let me know if this helps!

Loop Expression Engine Entries?

I need some assistance with looping expression engine entries. I've hit a brick wall with a website i've been working on. Basically the site has 6 latest projects at the bottom with next and prev icons to the left and right. When you reach the end of the projects there is a back to start of projects button that brings the user back to the start of the projects... well, the client doesn't want this anymore and just wants the entries have an infinite loop!
Is this possible with EE, is there an add-on for looping entries I could use?
My code is:
{exp:channel:next_entry category_group="1" category="{categories}{category_id}|{/categories}"}
<a class="rightNav" href="{id_path='projects-test/view'}" style="color:#000;"><<</a>
{/exp:channel:next_entry}
{embed="projects-test/related" stop_before="{entry_date format="%Y-%m-%d %H:%i"}" category_id="{categories show_group="1" limit="1"}{category_id}{/categories}"}
{exp:channel:prev_entry category_group="1" category="{categories}{category_id}|{/categories}"}
<a class="leftNav" href="{id_path='projects-test/view'}" style="color:#000;">>></a>
{/exp:channel:prev_entry}
{/exp:channel:entries}
Related template code:
{exp:channel:entries channel="project" limit="6" category_group="1" stop_before="{embed:stop_before}" related_categories_mode="yes" custom_fields="yes"}
{if count == "1"}<ul id="filmStrip">{/if}
<li>
{exp:imgsizer:size src="{project_image}" height="68px" width="137px"}
<img src="{sized}" height="{height}" width="{width}" alt=""/>
{/exp:imgsizer:size}
<p class="thumbTitle">{title}</p>
</li>
{if count == total_results}</ul>{/if}
{/exp:channel:entries}
This plugin may do the trick for you.
Usage probably looks like this:
{exp:bbr_prevnext_entry current_entry_id="{entry_id}" category="{categories}{category_id}|{/categories}" channel_name="project" orderby="entry_date" sort="desc" return_fields="entry_id" cycle="yes"}
<a class="rightNav" href="/projects-test/view/{next_entry_id}" style="color:#000;"><<</a>
{/exp:bbr_prevnext_entry}
{embed="projects-test/related" stop_before="{entry_date format="%Y-%m-%d %H:%i"}" category_id="{categories show_group="1" limit="1"}{category_id}{/categories}"}
{exp:bbr_prevnext_entry current_entry_id="{entry_id}" category="{categories}{category_id}|{/categories}" channel_name="project" orderby="entry_date" sort="desc" return_fields="entry_id" cycle="yes"}
<a class="leftNav" href="/projects-test/view/{prev_entry_id}" style="color:#000;">>></a>
{/exp:bbr_prevnext_entry}

Categories